repo restructure
All checks were successful
Build Docker Image / build (push) Successful in 1m3s

This commit is contained in:
Tudor Sitaru
2025-10-14 21:58:54 +01:00
parent e062b51b4b
commit d8637ac2ea
69 changed files with 781 additions and 4710 deletions

View File

@@ -0,0 +1,185 @@
#!/usr/bin/env python3
"""
Demo Asset Tracking
This script demonstrates the asset tracking functionality by showing
how new and modified assets are detected and downloaded.
"""
import asyncio
import logging
import sys
import os
from pathlib import Path
# Add the parent directory to the path so we can import modules
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from src.auth_manager import AuthManager
from src.asset_tracker import AssetTracker
from src.image_downloader import ImageDownloader
async def demo_asset_tracking():
"""Demonstrate asset tracking functionality."""
print("🎯 ParentZone Asset Tracking Demo")
print("=" * 60)
# Configuration
email = "tudor.sitaru@gmail.com"
password = "mTVq8uNUvY7R39EPGVAm@"
output_dir = "downloaded_images"
# Setup logging
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
try:
print("\n🔐 Step 1: Testing Authentication")
print("-" * 40)
# Test authentication first
auth_manager = AuthManager()
success = await auth_manager.login(email, password)
if not success:
print("❌ Authentication failed!")
return False
print(f"✅ Authentication successful!")
print(f" User: {auth_manager.user_name}")
print(f" Provider: {auth_manager.provider_name}")
print(f"\n📊 Step 2: Check Current Asset Status")
print("-" * 40)
# Check current asset tracker status
tracker = AssetTracker(storage_dir=output_dir)
stats = tracker.get_stats()
print(f"Current local assets:")
print(f" Total tracked: {stats['total_tracked_assets']}")
print(f" Existing files: {stats['existing_files']}")
print(f" Missing files: {stats['missing_files']}")
print(f" Total size: {stats['total_size_mb']} MB")
print(f"\n⬇️ Step 3: Download Assets (First Run)")
print("-" * 40)
print("This will download new assets and skip existing ones...")
# Create downloader with asset tracking enabled
downloader = ImageDownloader(
api_url="https://api.parentzone.me",
list_endpoint="/v1/media/list",
download_endpoint="/v1/media",
output_dir=output_dir,
email=email,
password=password,
track_assets=True,
max_concurrent=3,
)
# First download run
print("\n🚀 Starting download...")
await downloader.download_all_assets()
# Show results
print(f"\n📈 First Run Results:")
print(f" Total assets found: {downloader.stats['total']}")
print(f" Successfully downloaded: {downloader.stats['successful']}")
print(f" Failed downloads: {downloader.stats['failed']}")
print(f" Skipped (existing): {downloader.stats['skipped']}")
if downloader.asset_tracker:
updated_stats = downloader.asset_tracker.get_stats()
print(f"\n📊 Updated Asset Status:")
print(f" Total tracked: {updated_stats['total_tracked_assets']}")
print(f" Existing files: {updated_stats['existing_files']}")
print(f" Total size: {updated_stats['total_size_mb']} MB")
print(f"\n🔄 Step 4: Second Run (Should Skip All)")
print("-" * 40)
print("Running again - should detect no new assets...")
# Reset stats for second run
downloader.stats = {"total": 0, "successful": 0, "failed": 0, "skipped": 0}
# Second download run
await downloader.download_all_assets()
print(f"\n📈 Second Run Results:")
print(f" Assets to download: {downloader.stats['total']}")
print(f" New downloads: {downloader.stats['successful']}")
if downloader.stats["total"] == 0:
print(" ✅ Perfect! No new assets found - all are up to date!")
else:
print(f" Downloaded: {downloader.stats['successful']}")
print(f" Failed: {downloader.stats['failed']}")
print(f"\n🧹 Step 5: Cleanup and Final Stats")
print("-" * 40)
if downloader.asset_tracker:
# Cleanup any missing files
print("Checking for missing files...")
downloader.asset_tracker.cleanup_missing_files()
# Final statistics
final_stats = downloader.asset_tracker.get_stats()
print(f"\n📊 Final Statistics:")
print(f" Total tracked assets: {final_stats['total_tracked_assets']}")
print(f" Successful downloads: {final_stats['successful_downloads']}")
print(f" Failed downloads: {final_stats['failed_downloads']}")
print(f" Existing files: {final_stats['existing_files']}")
print(f" Total size: {final_stats['total_size_mb']} MB")
print(f"\n✨ Demo completed successfully!")
print("=" * 60)
return True
except Exception as e:
print(f"❌ Demo failed with error: {e}")
import traceback
traceback.print_exc()
return False
def show_usage():
"""Show usage information."""
print("Asset Tracking Demo")
print("=" * 30)
print("This demo shows how the asset tracking system:")
print("• Identifies new assets to download")
print("• Skips already downloaded assets")
print("• Detects modified assets")
print("• Maintains local metadata")
print()
print("Usage:")
print(" python3 demo_asset_tracking.py # Run the demo")
print(" python3 demo_asset_tracking.py --help # Show this help")
print()
print("The demo will:")
print("1. Authenticate with ParentZone API")
print("2. Check current local asset status")
print("3. Download new/modified assets (first run)")
print("4. Run again to show efficient skipping")
print("5. Display final statistics")
async def main():
"""Main function."""
if len(sys.argv) > 1 and sys.argv[1] in ["--help", "-h"]:
show_usage()
return 0
print("🚀 Starting ParentZone Asset Tracking Demo...")
success = await demo_asset_tracking()
return 0 if success else 1
if __name__ == "__main__":
exit(asyncio.run(main()))

View File

@@ -0,0 +1,158 @@
#!/usr/bin/env python3
"""
Demo Snapshot Downloader
This script demonstrates the snapshot downloader functionality by
downloading a small set of snapshots and generating an HTML report.
"""
import asyncio
import logging
import sys
import os
from datetime import datetime, timedelta
# Add the current directory to the path so we can import modules
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from snapshot_downloader import SnapshotDownloader
async def demo_snapshot_download():
"""Demonstrate snapshot downloading functionality."""
print("🎯 ParentZone Snapshot Downloader Demo")
print("=" * 60)
# Configuration
email = "tudor.sitaru@gmail.com"
password = "mTVq8uNUvY7R39EPGVAm@"
output_dir = "demo_snapshots"
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
try:
print("\n🔐 Step 1: Initialize Snapshot Downloader")
print("-" * 40)
downloader = SnapshotDownloader(
output_dir=output_dir,
email=email,
password=password
)
print(f"✅ Downloader initialized")
print(f" Output directory: {output_dir}")
print(f" Authentication: Email/Password")
print(f"\n📊 Step 2: Download Snapshots (Limited)")
print("-" * 40)
print("Downloading snapshots with limits for demo...")
# Download snapshots with limits for demo
html_file = await downloader.download_snapshots(
type_ids=[15], # Snapshot type
date_from="2024-01-01", # Start of 2024
date_to="2024-03-31", # First quarter only
max_pages=3 # Limit to first 3 pages for demo
)
if html_file:
print(f"\n✅ Demo completed successfully!")
print(f"📄 HTML Report: {html_file}")
# Print statistics
print(f"\n📈 Demo Results:")
print(f" Total snapshots: {downloader.stats['total_snapshots']}")
print(f" Pages fetched: {downloader.stats['pages_fetched']}")
print(f" Failed requests: {downloader.stats['failed_requests']}")
print(f" Generated files: {downloader.stats['generated_files']}")
print(f"\n🌐 How to View:")
print(f"1. Open your file browser")
print(f"2. Navigate to: {html_file}")
print(f"3. Double-click the HTML file to open in browser")
print(f"4. Use the search box to find specific snapshots")
print(f"5. Click snapshot titles to expand/collapse details")
else:
print("⚠️ No snapshots found for the demo period")
return True
except Exception as e:
print(f"❌ Demo failed with error: {e}")
import traceback
traceback.print_exc()
return False
def show_demo_info():
"""Show information about the demo."""
print("\n" + "=" * 60)
print("📋 SNAPSHOT DOWNLOADER DEMO INFO")
print("=" * 60)
print("\n🎯 What This Demo Does:")
print("• Authenticates with ParentZone API using login credentials")
print("• Downloads snapshots (daily events) from Q1 2024")
print("• Generates an interactive HTML report")
print("• Shows pagination handling (limited to 3 pages)")
print("• Demonstrates error handling and statistics")
print("\n📄 HTML Report Features:")
print("• Chronological listing of all snapshots")
print("• Search functionality to find specific events")
print("• Collapsible sections for detailed metadata")
print("• Images and attachments (if available)")
print("• Mobile-responsive design")
print("• Raw JSON data for each snapshot (expandable)")
print("\n⚙️ Technical Features Demonstrated:")
print("• API authentication flow")
print("• Pagination handling across multiple pages")
print("• HTML escaping for security")
print("• Date formatting and parsing")
print("• Error handling and logging")
print("• Statistics tracking")
print("\n🔧 Configuration Options Available:")
print("• Date range filtering")
print("• Type ID filtering (default: 15 for snapshots)")
print("• Page limits for testing")
print("• Custom output directories")
print("• API key or email/password authentication")
def main():
"""Main demo function."""
show_demo_info()
print("\n" + "=" * 60)
print("🚀 STARTING DEMO")
print("=" * 60)
success = asyncio.run(demo_snapshot_download())
if success:
print("\n" + "=" * 60)
print("🎉 DEMO COMPLETED SUCCESSFULLY!")
print("=" * 60)
print("✅ Snapshot downloader is working correctly")
print("✅ HTML report generated with interactive features")
print("✅ Pagination and authentication working")
print("\n💡 Try the full downloader with:")
print(" python3 snapshot_downloader.py --email your@email.com --password yourpass")
print(" python3 config_snapshot_downloader.py --config snapshot_config.json")
else:
print("\n❌ Demo failed - check error messages above")
return 1
return 0
if __name__ == "__main__":
exit(main())