Use seeparklib.openweathermap.
[chrisu/seepark.git] / owm.py
diff --git a/owm.py b/owm.py
index 27b9f08ed51658b3346703c742584e7bbcd4cf5f..323ab9d6417635fa8877dc0ee95cafd68110f1d8 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -8,31 +8,15 @@
 
 from pprint import pprint
 import argparse
-import requests
 import configparser
 import os
 import csv
 import datetime
 import math
-import sys
+from seeparklib.openweathermap import openweathermap_json
 
-baseurl = 'http://api.openweathermap.org/data/2.5/weather'
 debug = False
 
-def getweather(apikey, cityid):
-    query = baseurl + '?units=metric&APPID={}&id={}&lang=de'.format(apikey, cityid)
-    try:
-        response = requests.get(query)
-        if response.status_code != 200:
-            response = 'N/A'
-            return response
-        else:
-            weatherdata = response.json()
-            return weatherdata
-    except requests.exceptions.RequestException as error:
-        print (error)
-        sys.exit(1)
-
 
 def fromtimestamp(timestamp, format):
     return datetime.datetime.fromtimestamp(timestamp).strftime(format)
@@ -97,7 +81,7 @@ def main(configfile):
     cityid = config.get('openweathermap', 'cityid')
     csvfile = config.get("openweathermap", 'csvfilename')
 
-    weather_raw = getweather(apikey, cityid)
+    weather_raw = openweathermap_json(apikey, cityid)
     if debug:
         pprint(weather_raw)
     weather = extractweatherdata(weather_raw)