Spaces:
Running
Running
Commit
·
80e1440
1
Parent(s):
11f9dba
Update main.py
Browse files
main.py
CHANGED
@@ -35,6 +35,18 @@ def get_ip_info(ip_address):
|
|
35 |
except Exception as e:
|
36 |
return {"error": str(e)}
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
def latlon_to_pixel(loc):
|
39 |
latitude = float(loc.split(',')[0])
|
40 |
longitude = float(loc.split(',')[1])
|
@@ -87,10 +99,9 @@ def index():
|
|
87 |
session['current_feed'] = feed
|
88 |
|
89 |
ip = ''.join(url.split('//')[-1]).split(':')[0]
|
90 |
-
info =
|
91 |
-
country =
|
92 |
name = (info['city'] + ", " + info['region'] + ", " + country).lower()
|
93 |
-
org = info['org'].lower()
|
94 |
timezone = pytz.timezone(info['timezone'])
|
95 |
time = dt.datetime.now(timezone)
|
96 |
time = time.strftime("%I:%M:%S %p")
|
@@ -109,7 +120,6 @@ def index():
|
|
109 |
timezone=timezone,
|
110 |
ip=ip,
|
111 |
ip_link=ip_link,
|
112 |
-
org=org,
|
113 |
loc=loc,
|
114 |
loc_link=loc_link,
|
115 |
X=X,
|
|
|
35 |
except Exception as e:
|
36 |
return {"error": str(e)}
|
37 |
|
38 |
+
from geolite2 import geolite2
|
39 |
+
def get_location(ip):
|
40 |
+
reader = geolite2.reader()
|
41 |
+
location = reader.get(ip)
|
42 |
+
geolite2.close()
|
43 |
+
if location and 'location' in location:
|
44 |
+
return {'country': location['country']['names']['en'],
|
45 |
+
'city': location['city']['names']['en'],
|
46 |
+
'region': location['subdivisions'][0]['names']['en'] if len(location['subdivisions'])>0 else '',
|
47 |
+
'loc': str(location['location']['longitude']) + ',' + str(location['location']['latitude']),
|
48 |
+
'timezone': location['location']['time_zone']}
|
49 |
+
|
50 |
def latlon_to_pixel(loc):
|
51 |
latitude = float(loc.split(',')[0])
|
52 |
longitude = float(loc.split(',')[1])
|
|
|
99 |
session['current_feed'] = feed
|
100 |
|
101 |
ip = ''.join(url.split('//')[-1]).split(':')[0]
|
102 |
+
info = get_location(ip)
|
103 |
+
country = info['country']
|
104 |
name = (info['city'] + ", " + info['region'] + ", " + country).lower()
|
|
|
105 |
timezone = pytz.timezone(info['timezone'])
|
106 |
time = dt.datetime.now(timezone)
|
107 |
time = time.strftime("%I:%M:%S %p")
|
|
|
120 |
timezone=timezone,
|
121 |
ip=ip,
|
122 |
ip_link=ip_link,
|
|
|
123 |
loc=loc,
|
124 |
loc_link=loc_link,
|
125 |
X=X,
|