Commit
·
3a05da9
1
Parent(s):
6004ee0
Update main.py
Browse files
main.py
CHANGED
|
@@ -40,11 +40,11 @@ def get_location(ip):
|
|
| 40 |
reader = geolite2.reader()
|
| 41 |
location = reader.get(ip)
|
| 42 |
geolite2.close()
|
| 43 |
-
if location
|
| 44 |
return {'country': location['country']['names']['en'],
|
| 45 |
'city': location['city']['names']['en'] if 'city' in location else '',
|
| 46 |
'region': location['subdivisions'][0]['names']['en'] if 'subdivisions' in location else '',
|
| 47 |
-
'loc': str(location['location']['
|
| 48 |
'timezone': location['location']['time_zone'] if 'time_zone' in location['location'] else 'America/New_York'}
|
| 49 |
|
| 50 |
def latlon_to_pixel(loc):
|
|
@@ -101,7 +101,7 @@ def index():
|
|
| 101 |
ip = ''.join(url.split('//')[-1]).split(':')[0]
|
| 102 |
print('IP:',ip)
|
| 103 |
info = get_location(ip)
|
| 104 |
-
country = info['country']
|
| 105 |
name = (info['city'] + ", " + info['region'] + ", " + country).lower()
|
| 106 |
timezone = pytz.timezone(info['timezone'])
|
| 107 |
time = dt.datetime.now(timezone)
|
|
|
|
| 40 |
reader = geolite2.reader()
|
| 41 |
location = reader.get(ip)
|
| 42 |
geolite2.close()
|
| 43 |
+
if location:
|
| 44 |
return {'country': location['country']['names']['en'],
|
| 45 |
'city': location['city']['names']['en'] if 'city' in location else '',
|
| 46 |
'region': location['subdivisions'][0]['names']['en'] if 'subdivisions' in location else '',
|
| 47 |
+
'loc': str(location['location']['latitude']) + ',' + str(location['location']['longitude']),
|
| 48 |
'timezone': location['location']['time_zone'] if 'time_zone' in location['location'] else 'America/New_York'}
|
| 49 |
|
| 50 |
def latlon_to_pixel(loc):
|
|
|
|
| 101 |
ip = ''.join(url.split('//')[-1]).split(':')[0]
|
| 102 |
print('IP:',ip)
|
| 103 |
info = get_location(ip)
|
| 104 |
+
country = info['country'].lower()
|
| 105 |
name = (info['city'] + ", " + info['region'] + ", " + country).lower()
|
| 106 |
timezone = pytz.timezone(info['timezone'])
|
| 107 |
time = dt.datetime.now(timezone)
|