summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--forecast.conf5
-rw-r--r--forecastWU.conf75
-rw-r--r--weather.json1
-rwxr-xr-xweather.lua121
4 files changed, 199 insertions, 3 deletions
diff --git a/forecast.conf b/forecast.conf
index 7fe13bd..b5b2468 100644
--- a/forecast.conf
+++ b/forecast.conf
@@ -70,6 +70,5 @@ template7 600
template8 900
TEXT
-${offset -5}${color3}${font StyleBats:style=CleanCut:size=12}q ${voffset -2}${font Bitstream Vera Sans Mono:style=Bold:size=11}Weather${font} ${goto 120}${hr}${color1}
-${execpi $template7 conkyForecastWU -C /usr/share/conkyforecast/conkyForecastWU.config --location=zmw:00000.24.10727 --template=/etc/conky/forecastWU.template}
-${voffset -200}
+#${alignc}${execpi 1800 /etc/conky/weather.lua}
+#${voffset -200}
diff --git a/forecastWU.conf b/forecastWU.conf
new file mode 100644
index 0000000..7fe13bd
--- /dev/null
+++ b/forecastWU.conf
@@ -0,0 +1,75 @@
+update_interval 60
+alignment top_right
+double_buffer yes
+
+background no
+use_xft yes
+xftfont Bitstream Vera Sans Mono:size=9
+xftalpha 0.8
+
+update_interval 1.0
+total_run_times 0
+
+# Minimum size of text area
+minimum_size 440 0
+maximum_width 440
+
+draw_shades yes
+draw_outline no
+draw_borders no
+draw_graph_borders yes
+stippled_borders 8
+border_inner_margin 4
+border_width 1
+
+# own window options
+own_window yes
+#own_window_transparent yes
+own_window_type override
+own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
+own_window_colour 21449c
+
+
+# Gap between borders of screen and text
+# same thing as passing -x at command line
+#gap_x 280
+#gap_x -2280
+#gap_y 0
+
+gap_y 720
+gap_x -4460
+
+# Force UTF8? note that UTF8 support required XFT
+override_utf8_locale yes
+
+# Add spaces to keep things from moving about? This only affects certain objects.
+use_spacer right
+
+# Default colors and also border colors
+default_color white
+default_shade_color black
+default_outline_color white
+
+color1 white
+#color2 6892C6
+color2 orange
+#color3 FC8820
+color3 yellow
+color4 78BF39
+color5 CC0000
+
+text_buffer_size 2048
+
+# 5 - interactive apps (xmms)
+# 6 - local apps
+# 7 - networking
+# 8 - ping + remote scripts
+template5 120
+template6 300
+template7 600
+template8 900
+
+TEXT
+${offset -5}${color3}${font StyleBats:style=CleanCut:size=12}q ${voffset -2}${font Bitstream Vera Sans Mono:style=Bold:size=11}Weather${font} ${goto 120}${hr}${color1}
+${execpi $template7 conkyForecastWU -C /usr/share/conkyforecast/conkyForecastWU.config --location=zmw:00000.24.10727 --template=/etc/conky/forecastWU.template}
+${voffset -200}
diff --git a/weather.json b/weather.json
new file mode 100644
index 0000000..5c0b90d
--- /dev/null
+++ b/weather.json
@@ -0,0 +1 @@
+{"wind":{"speed":1.48,"deg":297.757},"cod":200,"id":2878676,"timestamp":"20190705204731","name":"Leopoldshafen","coord":{"lon":8.4,"lat":49.1},"timezone":7200,"sys":{"message":0.0083,"type":1,"country":"DE","id":1802,"sunset":1562355197,"sunrise":1562297290},"main":{"pressure":1015,"temp_max":23.89,"temp_min":20,"humidity":52,"temp":21.52},"dt":1562359651,"visibility":10000,"weather":[{"id":800,"icon":"01n","main":"Clear","description":"clear sky"}],"base":"stations","clouds":{"all":1}} \ No newline at end of file
diff --git a/weather.lua b/weather.lua
new file mode 100755
index 0000000..9364167
--- /dev/null
+++ b/weather.lua
@@ -0,0 +1,121 @@
+#!/usr/bin/env lua
+-- load the http socket module
+http = require("socket.http")
+-- load the json module
+json = require("json")
+
+api_url = "http://api.openweathermap.org/data/2.5/weather?"
+
+-- http://openweathermap.org/help/city_list.txt , http://openweathermap.org/find
+cityid = "2878676"
+
+-- metric or imperial
+cf = "metric"
+
+-- get an open weather map api key: http://openweathermap.org/appid
+apikey = "3df14dd57e705f30c04157c2f6260939"
+
+-- measure is °C if metric and °F if imperial
+measure = '°' .. (cf == 'metric' and 'C' or 'F')
+wind_units = (cf == 'metric' and 'kph' or 'mph')
+
+-- Unicode weather symbols to use
+icons = {
+ ["01"] = "☀️",
+ ["02"] = "🌤",
+ ["03"] = "🌥",
+ ["04"] = "☁",
+ ["09"] = "🌧",
+ ["10"] = "🌦",
+ ["11"] = "🌩",
+ ["13"] = "🌨",
+ ["50"] = "🌫",
+}
+
+currenttime = os.date("!%Y%m%d%H%M%S")
+
+file_exists = function (name)
+ f=io.open(name,"r")
+ if f~=nil then
+ f:close()
+ return true
+ else
+ return false
+ end
+end
+
+if file_exists("/etc/conky/weather.json") then
+ cache = io.open("/etc/conky/weather.json","r")
+ data = json.decode(cache:read())
+ cache:close()
+ timepassed = os.difftime(currenttime, data.timestamp)
+else
+ timepassed = 6000
+end
+
+makecache = function (s)
+ cache = io.open("/etc/conky/weather.json", "w+")
+ s.timestamp = currenttime
+ save = json.encode(s)
+ cache:write(save)
+ cache:close()
+end
+
+if timepassed < 3600 then
+ response = data
+else
+ print (("%sid=%s&units=%s&APPID=%s"):format(api_url, cityid, cf, apikey))
+ weather = http.request(("%sid=%s&units=%s&APPID=%s"):format(api_url, cityid, cf, apikey))
+ print(weather)
+ if weather then
+ response = json.decode(weather)
+ makecache(response)
+ else
+ response = data
+ end
+end
+
+math.round = function (n)
+ return math.floor(n + 0.5)
+end
+
+degrees_to_direction = function (d)
+ val = math.round(d/22.5)
+ directions={"N","NNE","NE","ENE",
+ "E","ESE", "SE", "SSE",
+ "S","SSW","SW","WSW",
+ "W","WNW","NW","NNW"}
+ return directions[val % 16]
+end
+
+temp = response.main.temp
+conditions = response.weather[1].description
+icon2 = response.weather[1].id
+icon = response.weather[1].icon:sub(1, 2)
+humidity = response.main.humidity
+wind = response.wind.speed
+deg = degrees_to_direction(response.wind.deg)
+sunrise = os.date("%H:%M %p", response.sys.sunrise)
+sunset = os.date("%H:%M %p", response.sys.sunset)
+
+conky_text = [[
+${font Symbola:size=48}%s ${voffset -10}${font :size=20}${color1}%s${font}${voffset -5}%s${color}
+${alignc}${voffset 28} %s
+
+${alignc}Humidity: ${color1}%s%%${color}
+${alignc}Wind: ${color1}%s%s %s${color}
+
+${alignc}${font Symbola:size=20}─⯊─${font}
+${alignc}${color1}%s${color} | ${color1}%s${color}
+]]
+io.write((conky_text):format(icons[icon],
+ math.round(temp),
+ measure,
+ conditions,
+ humidity,
+ math.round(wind),
+ wind_units,
+ deg,
+ sunrise,
+ sunset)
+)