Now fetches current external ip and uses geoip2 to get the information for current ip

This commit is contained in:
2017-07-27 22:15:23 +02:00
parent d6fda82090
commit 56ddadae16

30
term_weather.py Normal file → Executable file
View File

@@ -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)
fire.Fire(TermWeather())