Files
memories/backend/data_importer.py
maq ae0a6b575b
Some checks failed
CI/CD Pipeline / test (3.1) (push) Has been cancelled
CI/CD Pipeline / lint (push) Has been cancelled
CI/CD Pipeline / deploy (push) Has been cancelled
Initial commit: Complete Memories app with Leaflet map, backend fixes, enhancements, and docs
2025-11-04 21:52:45 -08:00

28 lines
1.1 KiB
Python

import json
import datetime
from models import Location
class GoogleTakeoutImporter:
def import_locations(self, json_filepath: str) -> list[Location]:
locations = []
try:
with open(json_filepath, 'r', encoding='utf-8') as f:
data = json.load(f)
for loc_data in data.get('locations', []):
timestamp_ms = int(loc_data['timestampMs'])
timestamp = datetime.datetime.fromtimestamp(timestamp_ms / 1000.0)
latitude = loc_data['latitudeE7'] / 1e7
longitude = loc_data['longitudeE7'] / 1e7
locations.append({
'latitude': latitude,
'longitude': longitude,
'timestamp': timestamp
})
except FileNotFoundError:
print(f"Error: File not found: {json_filepath}")
except json.JSONDecodeError:
print("Error: Invalid JSON format.")
except Exception as e:
print(f"An unexpected error occurred during import: {e}")
return locations