diff options
Diffstat (limited to 'scripts/weather.py')
-rw-r--r-- | scripts/weather.py | 46 |
1 files changed, 0 insertions, 46 deletions
diff --git a/scripts/weather.py b/scripts/weather.py deleted file mode 100644 index f6be64a..0000000 --- a/scripts/weather.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/python - -import requests -import os - -delim="|" - -# Check for an internet connection -url='http://www.google.com/' -timeout=5 -try: - _ = requests.get(url, timeout=timeout) - internet = True -except requests.ConnectionError: - internet = False - -#COORDINATES = open("/usr/share/geolocate/.location", 'r').read() -#LOCATION = "lat=" + COORDINATES.replace(":","&lon=") - -API_KEY = "756edce7e9d4c385ef9499a53492678c" -UNITS = "Metric" -UNIT_KEY = "C" -#UNIT_KEY = "F" -LANG = "en" -#LANG = "nl" -#LANG = "hu" -if internet == True: - COORDINATES = os.popen("geolocate").read() - LOCATION = "lat=" + COORDINATES.replace(":","&lon=") - - API="http://api.openweathermap.org/data/2.5/weather?{}&lang={}&appid={}&units={}".format(LOCATION.strip(), LANG, API_KEY, UNITS) - REQ = requests.get(API) - #REQ = requests.get("http://api.openweathermap.org/data/2.5/weather?lat=50.84660&lon=4.35280&lang=en&appid=756edce7e9d4c385ef9499a53492678c&units=Metric") - try: - # HTTP CODE = OK - if REQ.status_code == 200: - CURRENT = REQ.json()["weather"][0]["description"].capitalize() - TEMP = int(float(REQ.json()["main"]["temp"])) - print(" {}, {} °{}".format(CURRENT, TEMP, UNIT_KEY)) - print(delim) - else: - print("Error: BAD HTTP STATUS CODE " + str(REQ.status_code)) - except (ValueError, IOError): - print("Error: Unable print the data") -else: - print("") |