forked from takattila/Clock-With-Weather-Conky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
68 lines (52 loc) · 2.75 KB
/
utils.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local utils = {}
function utils.get_weather_json()
return conky_parse(
"${exec curl -s '" .. settings.weather.api_url ..
"?q=" .. settings.weather.city .. "," .. settings.weather.language_code ..
"&lang=" .. settings.weather.lang ..
"&units=" .. settings.weather.units ..
"&appid=" .. settings.weather.api_key ..
"'}"
)
end
function utils.is_set_api_key(cr)
if settings.weather.api_key == nil then
local error_text_1 = "ERROR :("
text(cr, 0, 40, settings.appearance.font.transparency.light, error_text_1, settings.appearance.font.face, 40, CAIRO_FONT_WEIGHT_BOLD, settings.appearance.font.color.light)
local error_text_2 = "The 'OPENWEATHER_API_KEY' environment variable must be exported!"
text(cr, 0, 70, settings.appearance.font.transparency.light, error_text_2, settings.appearance.font.face, 20, CAIRO_FONT_WEIGHT_NORMAL, settings.appearance.font.color.dark)
local error_text_3 = " 1. Sign up on http://openweathermap.org to get an API key."
text(cr, 0, 90, settings.appearance.font.transparency.light, error_text_3, settings.appearance.font.face, 15, CAIRO_FONT_WEIGHT_NORMAL, settings.appearance.font.color.dark)
local error_text_4 = " 2. After the registration Check your e-mail, the API key should be sent!"
text(cr, 0, 110, settings.appearance.font.transparency.light, error_text_4, settings.appearance.font.face, 15, CAIRO_FONT_WEIGHT_NORMAL, settings.appearance.font.color.dark)
local error_text_5 = " 3. Open a terminal and export the API key:"
text(cr, 0, 130, settings.appearance.font.transparency.light, error_text_5, settings.appearance.font.face, 15, CAIRO_FONT_WEIGHT_NORMAL, settings.appearance.font.color.dark)
local error_text_6 = " export OPENWEATHER_API_KEY=<YOUR-API-KEY>"
text(cr, 0, 150, settings.appearance.font.transparency.light, error_text_6, settings.appearance.font.face, 15, CAIRO_FONT_WEIGHT_NORMAL, settings.appearance.font.color.dark)
print(
"\n" .. error_text_1
.. "\n" .. error_text_2
.. "\n" .. error_text_3
.. "\n" .. error_text_4
.. "\n" .. error_text_5
.. "\n" .. error_text_6
)
return false
end
return true
end
function utils.check_api_response_status(cr, obj)
if obj.cod == 200 then
return true
end
local error_text_1 = "ERROR :("
text(cr, 0, 40, settings.appearance.font.transparency.light, error_text_1, settings.appearance.font.face, 40, CAIRO_FONT_WEIGHT_BOLD, settings.appearance.font.color.light)
local error_text_2 = "- OpenWeatherMap API response: " .. obj.message
text(cr, 0, 70, settings.appearance.font.transparency.light, error_text_2, settings.appearance.font.face, 20, CAIRO_FONT_WEIGHT_NORMAL, settings.appearance.font.color.dark)
print(
"\n" .. error_text_1
.. "\n" .. error_text_2
)
return false
end
return utils