fix language swap

This commit is contained in:
lelo 2025-04-18 22:52:34 +00:00
parent 02c5bc8026
commit bd30745e43
2 changed files with 36 additions and 2 deletions

View File

@ -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
View 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()