summaryrefslogtreecommitdiff
path: root/.config/conky/weather.py
diff options
context:
space:
mode:
Diffstat (limited to '.config/conky/weather.py')
-rwxr-xr-x.config/conky/weather.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/.config/conky/weather.py b/.config/conky/weather.py
new file mode 100755
index 00000000..b6999846
--- /dev/null
+++ b/.config/conky/weather.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import urllib.request
+import json
+import datetime
+from pathlib import Path
+
+########################################################
+# CONFIGURATION
+########################################################
+# UNITY = f for fahrenheit, c for celsius or k for kelvin
+# API_KEY = free register in https://openweathermap.org
+# and get your token
+# CITY = your city name
+# COUNTRY = your country abbreviation: us, ru, br, etc..
+########################################################
+
+UNITY = "c"
+API_KEY = "b91400ad90f74c8cc0bccf5e2978aaca"
+CITY = "Montevideo"
+COUNTRY = "uy"
+
+########################################################
+main_url = "http://api.openweathermap.org/data/2.5/weather?"
+url = main_url+"APPID={}&q={},{}".format(API_KEY,CITY,COUNTRY)
+print(url)
+metrics = {"k":"&units=default","c":"&units=metric","f":"&units=imperial"}
+for key,value in metrics.items():
+ if UNITY == key:
+ url += value
+request = urllib.request.urlopen(url)
+if request.status != 200:
+ exit(0)
+response = request.read()
+
+j = json.loads(response.decode("utf-8"))
+home = str(Path.home())
+weather = open(home+"/.cache/weather.txt",'w+')
+weather.write("city>"+j["name"]+"\n")
+weather.write("country>"+j["sys"]["country"]+"\n")
+weather.write("temp>"+str(j["main"]["temp"])+"\n")
+weather.write("description>"+j["weather"][0]["description"].capitalize()+"\n")
+weather.write("min>"+str(j["main"]["temp_min"])+"\n")
+weather.write("max>"+str(j["main"]["temp_max"])+"\n")
+weather.write("humidity>"+str(j["main"]["humidity"])+"\n")
+weather.write("pressure>"+str(j["main"]["pressure"])+"\n")
+weather.write("wind>"+str(j["wind"]["speed"])+"\n")
+weather.write("update>"+datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')+"\n")
+
+weather.close()