From 63b54727902a2517e9f8f3021fcb0ae58f7d25b6 Mon Sep 17 00:00:00 2001 From: gze Date: Mon, 17 Jul 2017 18:57:55 +0000 Subject: [PATCH] read location from geo IP or pass is as argv --- w.py | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/w.py b/w.py index 5a957e5..5b1b1e9 100644 --- a/w.py +++ b/w.py @@ -9,26 +9,47 @@ from datetime import date, datetime, time, timedelta from pprint import pprint import platform from urllib2 import urlopen - -url = 'http://ipinfo.io/json' -response = urlopen(url) -data = json.load(response) - -IP=data['ip'] -org=data['org'] -city = data['city'] -country=data['country'] -region=data['region'] - -print 'Your IP detail\n ' -print 'IP : {4} \nRegion : {1} \nCountry : {2} \nCity : {3} \nOrg : {0}'.format(org,region,country,city,IP) +from pprint import pprint +def getLocation(): + url = 'http://ipinfo.io/json' + response = urlopen(url) + data = json.load(response) + IP=data['ip'] + org=data['org'] + city = data['city'] + country=data['country'] + region=data['region'] + return data + + +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')