read location from geo IP or pass is as argv
This commit is contained in:
27
w.py
27
w.py
@@ -9,7 +9,11 @@ from datetime import date, datetime, time, timedelta
|
|||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import platform
|
import platform
|
||||||
from urllib2 import urlopen
|
from urllib2 import urlopen
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getLocation():
|
||||||
url = 'http://ipinfo.io/json'
|
url = 'http://ipinfo.io/json'
|
||||||
response = urlopen(url)
|
response = urlopen(url)
|
||||||
data = json.load(response)
|
data = json.load(response)
|
||||||
@@ -19,16 +23,33 @@ org=data['org']
|
|||||||
city = data['city']
|
city = data['city']
|
||||||
country=data['country']
|
country=data['country']
|
||||||
region=data['region']
|
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')
|
os.system('clear')
|
||||||
|
|
||||||
location = 1 # Reykjavik
|
location = wstation_int
|
||||||
|
|
||||||
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user