Compare commits
3 Commits
5a0935b8f4
...
bd30745e43
| Author | SHA1 | Date | |
|---|---|---|---|
| bd30745e43 | |||
| 02c5bc8026 | |||
| e9125098f8 |
@ -44,7 +44,7 @@ def lookup_location(ip):
|
|||||||
response = geoReader.city(ip)
|
response = geoReader.city(ip)
|
||||||
country = response.country.name if response.country.name else "Unknown"
|
country = response.country.name if response.country.name else "Unknown"
|
||||||
city = response.city.name if response.city.name else "Unknown"
|
city = response.city.name if response.city.name else "Unknown"
|
||||||
return country, city
|
return city, country
|
||||||
except Exception:
|
except Exception:
|
||||||
return "Unknown", "Unknown"
|
return "Unknown", "Unknown"
|
||||||
|
|
||||||
@ -455,7 +455,7 @@ def dashboard():
|
|||||||
location_data_dict[key] = location_data_dict.get(key, 0) + cnt
|
location_data_dict[key] = location_data_dict.get(key, 0) + cnt
|
||||||
|
|
||||||
location_data = [
|
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()
|
for k, v in location_data_dict.items()
|
||||||
]
|
]
|
||||||
location_data.sort(key=lambda x: x['count'], reverse=True)
|
location_data.sort(key=lambda x: x['count'], reverse=True)
|
||||||
|
|||||||
@ -4,7 +4,19 @@
|
|||||||
# Load Configuration from json
|
# Load Configuration from json
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
CONFIG_FILE="folder_mount_config.json"
|
# Require the config‑file path as the first argument:
|
||||||
|
CONFIG_FILE="$1"
|
||||||
|
|
||||||
|
if [[ -z "$CONFIG_FILE" ]]; then
|
||||||
|
echo "[ERROR] No path to config file given"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure the file actually exists:
|
||||||
|
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||||
|
echo "[ERROR] Config file '$CONFIG_FILE' not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Ensure jq is installed before proceeding.
|
# Ensure jq is installed before proceeding.
|
||||||
if ! command -v jq >/dev/null 2>&1; then
|
if ! command -v jq >/dev/null 2>&1; then
|
||||||
|
|||||||
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