mirror of
https://github.com/KevinMidboe/termForecast.git
synced 2025-10-29 09:50:18 +00:00
Now fetches current external ip and uses geoip2 to get the information for current ip
This commit is contained in:
30
term_weather.py
Normal file → Executable file
30
term_weather.py
Normal file → Executable file
@@ -3,20 +3,42 @@
|
|||||||
# @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 21:33:30
|
# @Last Modified time: 2017-07-27 22:13:22
|
||||||
|
|
||||||
# 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 wheater description to icons
|
||||||
|
# Check internet connection in a strict way
|
||||||
|
|
||||||
import fire
|
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):
|
def fetch(self, town):
|
||||||
pass
|
print(town)
|
||||||
|
location = Location()
|
||||||
|
location.getCoordinates()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
fire.Fire(termWeather)
|
fire.Fire(TermWeather())
|
||||||
Reference in New Issue
Block a user