read location from geo IP or pass is as argv

This commit is contained in:
2017-07-17 18:57:55 +00:00
parent f5d6c66faa
commit 63b5472790

27
w.py
View File

@@ -9,7 +9,11 @@ from datetime import date, datetime, time, timedelta
from pprint import pprint
import platform
from urllib2 import urlopen
from pprint import pprint
def getLocation():
url = 'http://ipinfo.io/json'
response = urlopen(url)
data = json.load(response)
@@ -19,16 +23,33 @@ org=data['org']
city = data['city']
country=data['country']
region=data['region']
return data
print 'Your IP detail\n '
print 'IP : {4} \nRegion : {1} \nCountry : {2} \nCity : {3} \nOrg : {0}'.format(org,region,country,city,IP)
if len(sys.argv) < 2:
locationOf = getLocation()
s2s = locationOf['city']
else:
s2s = sys.argv[1]
with open('wstations.json') as data_file:
data = json.load(data_file)
for wstation, value in data.iteritems():
if wstation == s2s:
pprint(value)
wstation_int = value
os.system('clear')
location = 1 # Reykjavik
location = wstation_int
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')