fix language swap
This commit is contained in:
parent
02c5bc8026
commit
bd30745e43
@ -44,7 +44,7 @@ def lookup_location(ip):
|
||||
response = geoReader.city(ip)
|
||||
country = response.country.name if response.country.name else "Unknown"
|
||||
city = response.city.name if response.city.name else "Unknown"
|
||||
return country, city
|
||||
return city, country
|
||||
except Exception:
|
||||
return "Unknown", "Unknown"
|
||||
|
||||
@ -455,7 +455,7 @@ def dashboard():
|
||||
location_data_dict[key] = location_data_dict.get(key, 0) + cnt
|
||||
|
||||
location_data = [
|
||||
dict(country=k[0], city=k[1], count=v)
|
||||
dict(city=k[0], country=k[1], count=v)
|
||||
for k, v in location_data_dict.items()
|
||||
]
|
||||
location_data.sort(key=lambda x: x['count'], reverse=True)
|
||||
|
||||
34
swap_city_country.py
Normal file
34
swap_city_country.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python3
|
||||
import sqlite3
|
||||
|
||||
# — CONFIGURE —
|
||||
DB_NAME = 'access_log.db'
|
||||
INDICATORS = [
|
||||
"Germany",
|
||||
"Canada",
|
||||
"Paraguay",
|
||||
"Uruguay",
|
||||
"France",
|
||||
"Australia",
|
||||
"Ukraine",
|
||||
"India"
|
||||
]
|
||||
# — END CONFIG —
|
||||
|
||||
# connect exactly as you use elsewhere
|
||||
log_db = sqlite3.connect(DB_NAME, check_same_thread=False)
|
||||
|
||||
# build and run the swap
|
||||
placeholders = ",".join("?" for _ in INDICATORS)
|
||||
sql = f"""
|
||||
UPDATE file_access_log
|
||||
SET city = country,
|
||||
country = city
|
||||
WHERE city IN ({placeholders})
|
||||
"""
|
||||
cur = log_db.cursor()
|
||||
cur.execute(sql, INDICATORS)
|
||||
log_db.commit()
|
||||
|
||||
print(f"Swapped city↔country on {cur.rowcount} row{'s' if cur.rowcount!=1 else ''}.")
|
||||
log_db.close()
|
||||
Loading…
x
Reference in New Issue
Block a user