diff --git a/term_weather.py b/term_weather.py old mode 100644 new mode 100755 index fef5714..e4b8285 --- a/term_weather.py +++ b/term_weather.py @@ -3,20 +3,42 @@ # @Author: KevinMidboe # @Date: 2017-07-27 21:26:53 # @Last Modified by: KevinMidboe -# @Last Modified time: 2017-07-27 21:33:30 +# @Last Modified time: 2017-07-27 22:13:22 # TOD LIST # Get coordinates from IP # Fetch coordinates from YR # Parse return data # Match wheater description to icons +# Check internet connection in a strict way import fire +import geoip2.database +# from urllib2 import Request, urlopen, URLError +from requests import get -class termWeather(object): + +class Location(object): + def __init__(self): + self.reader = geoip2.database.Reader('conf/GeoLite2-City.mmdb') + self.latitude = None + self.longitude = None + + def getIP(self): + ip = get('https://api.ipify.org').text + return ip + + def getCoordinates(self): + ip = self.getIP() + print(self.reader.city(ip)) + + +class TermWeather(object): def fetch(self, town): - pass + print(town) + location = Location() + location.getCoordinates() if __name__ == '__main__': - fire.Fire(termWeather) \ No newline at end of file + fire.Fire(TermWeather()) \ No newline at end of file