#!/usr/bin/env python3 """ Script to reprocess all GPX files and update their statistics in the database """ from app import create_app, db from app.models import GPXFile from app.utils.gpx_processor import process_gpx_file import os def fix_gpx_statistics(): """Reprocess all GPX files to update their statistics""" app = create_app() with app.app_context(): gpx_files = GPXFile.query.all() print(f"Found {len(gpx_files)} GPX files to process...") updated_count = 0 for gpx_file in gpx_files: print(f"\nProcessing: {gpx_file.filename}") print(f"Post: {gpx_file.post.title}") print(f"Media folder: {gpx_file.post.media_folder}") # Try to process the file if process_gpx_file(gpx_file): print(f"✓ Updated - Distance: {gpx_file.total_distance}km, " f"Elevation: {gpx_file.elevation_gain}m, " f"Points: {gpx_file.total_points}") updated_count += 1 else: print(f"✗ Failed to process {gpx_file.filename}") # Commit all changes db.session.commit() print(f"\n=== Summary ===") print(f"Total GPX files: {len(gpx_files)}") print(f"Successfully updated: {updated_count}") print(f"Failed: {len(gpx_files) - updated_count}") if __name__ == "__main__": fix_gpx_statistics()