You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

64 lines
2.2 KiB

import os
import django
import logging
from pathlib import Path
# Setup Django environment
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.develop')
django.setup()
from django.core.cache import cache
from city_detection_ip import get_location_by_coordinates, SPECIAL_COORDINATES
def test_flow(lat, lon):
print(f"\n{'='*60}")
print(f"DEBUGGING REVERSE GEOFLOW FOR: ({lat}, {lon})")
print(f"{'='*60}")
# Step 1: Special Coordinates Check
print("\n[STEP 1] Checking Special Coordinates...")
is_special = False
for s_lat, s_lon in SPECIAL_COORDINATES:
if abs(lat - s_lat) < 0.001 and abs(lon - s_lon) < 0.001:
print(f" MATCH FOUND! Coordinate ({lat}, {lon}) is a static placeholder.")
print(" Logic should skip DB lookup and use IP Detection instead.")
is_special = True
break
if not is_special:
print(" ✅ Not a special coordinate. Proceeding to cache.")
# Step 2: Cache Check
print("\n[STEP 2] Checking Cache...")
cache_key = f'geo_{round(lat, 2)}_{round(lon, 2)}'
cached_result = cache.get(cache_key)
if cached_result:
print(f" ✅ CACHE HIT! key: {cache_key}")
print(f" Result: {cached_result}")
else:
print(f" ❌ CACHE MISS. key: {cache_key}. Proceeding to Database.")
# Step 3: Application Logic Execution
print("\n[STEP 3] Executing Application Logic (city_detection_ip.py)...")
# Note: ensure logging is at INFO level to see app's internal logs
logging.getLogger('city_detection_ip').setLevel(logging.INFO)
result = get_location_by_coordinates(lat, lon)
print("\n[STEP 4] Final Result:")
if result:
print(f" SUCCESS: {result.get('city')}, {result.get('countryCode')}")
else:
print(" FAILED: No location found.")
print(f"{'='*60}\n")
if __name__ == "__main__":
import sys
if len(sys.argv) == 3:
try:
l1, l2 = float(sys.argv[1]), float(sys.argv[2])
test_flow(l1, l2)
except ValueError:
print("Please provide valid numbers for lat and lon.")
else:
# Default test (Karbaba coordinates)
test_flow(32.616, 44.034)