Now fetches the yr data for the current ip address. Not getting the symbol, so going to work on manual location input

This commit is contained in:
2017-07-27 23:05:09 +02:00
parent 478d9d6070
commit c3010de6ae

View File

@@ -3,26 +3,26 @@
# @Author: KevinMidboe # @Author: KevinMidboe
# @Date: 2017-07-27 21:26:53 # @Date: 2017-07-27 21:26:53
# @Last Modified by: KevinMidboe # @Last Modified by: KevinMidboe
# @Last Modified time: 2017-07-27 22:18:07 # @Last Modified time: 2017-07-27 23:03:19
# TOD LIST # TOD LIST
# Get coordinates from IP # Get coordinates from IP
# Fetch coordinates from YR # Fetch coordinates from YR
# Parse return data # Parse return data
# Match wheater description to icons # Match weather description to icons
# Check internet connection in a strict way # Check internet connection in a strict way
import fire import fire, json, geoip2.database, ssl
import geoip2.database from yr.libyr import Yr
# from urllib2 import Request, urlopen, URLError
from requests import get from requests import get
from pprint import pprint
class Location(object): class Location(object):
def __init__(self): def __init__(self):
self.reader = geoip2.database.Reader('conf/GeoLite2-City.mmdb') self.reader = geoip2.database.Reader('conf/GeoLite2-City.mmdb')
self.latitude = None self.lat = None
self.longitude = None self.long = None
def getIP(self): def getIP(self):
ip = get('https://api.ipify.org').text ip = get('https://api.ipify.org').text
@@ -32,16 +32,36 @@ class Location(object):
ip = self.getIP() ip = self.getIP()
ip_locaiton = self.reader.city(ip) ip_locaiton = self.reader.city(ip)
self.latitude = ip_locaiton.location.latitude self.lat = ip_locaiton.location.latitude
self.longitude = ip_locaiton.location.longitude self.long = ip_locaiton.location.longitude
class WeatherForcast(object):
"""docstring for WeatherForcast"""
def __init__(self, location):
self.location = location
def now(self):
lat = self.location.lat
long = self.location.long
print(lat, long)
weather = Yr(coordinates=(lat, long, 10))
now = json.loads(weather.now(as_json=True))
pprint(now)
class TermWeather(object): class TermWeather(object):
# Add now, forcast as args
def fetch(self, town): def auto(self):
print(town)
location = Location() location = Location()
location.getCoordinates() location.getCoordinates()
weatherForcast = WeatherForcast(location)
weatherForcast.now()
if __name__ == '__main__': if __name__ == '__main__':
ssl._create_default_https_context = ssl._create_unverified_context
fire.Fire(TermWeather()) fire.Fire(TermWeather())