From 56ddadae1607d457ca94e1a647a6ad31f95b3dcf Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Thu, 27 Jul 2017 22:15:23 +0200 Subject: [PATCH] Now fetches current external ip and uses geoip2 to get the information for current ip --- term_weather.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) mode change 100644 => 100755 term_weather.py 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