#!/usr/bin/env python3 """ Simple Profile Manager with API Integration Demo """ import json from user_profile_integration import UserProfileIntegration def main(): print("=== Profile Manager with API Integration ===") # Initialize the integration integration = UserProfileIntegration() print(f"\\nDevice ID: {integration.get_device_id()}") print(f"Active Profile: {integration.get_profile_name()}") print(f"API Server: {'Connected' if integration.api_enabled else 'Offline'}") while True: print("\\n=== MAIN MENU ===") print("1. Show Profile Info") print("2. View Online Leaderboard") print("3. View All Device Users") print("4. Submit Test Score") print("5. Create New Profile") print("6. Exit") try: choice = input("\\nSelect option (1-6): ").strip() if choice == "1": # Show profile info info = integration.get_profile_info() if info: print(f"\\n=== PROFILE INFO ===") for key, value in info.items(): print(f"{key.replace('_', ' ').title()}: {value}") else: print("No active profile loaded") elif choice == "2": # Show leaderboard if not integration.api_enabled: print("API server not available") continue print(f"\\n=== LEADERBOARD ===") leaderboard = integration.get_device_leaderboard(10) if leaderboard: for entry in leaderboard: print(f"{entry['rank']}. {entry['user_id']}: {entry['best_score']} pts ({entry['total_games']} games)") else: print("No scores recorded yet") elif choice == "3": # Show all users if not integration.api_enabled: print("API server not available") continue print(f"\\n=== DEVICE USERS ===") users = integration.get_all_device_users() if users: for user in users: print(f"{user['user_id']}: Best {user['best_score']}, {user['total_scores']} games") else: print("No users registered yet") elif choice == "4": # Submit test score if not integration.current_profile: print("No active profile to submit score for") continue try: score = int(input("Enter test score: ")) result = integration.update_game_stats(score, True) if result: print(f"Score {score} submitted successfully!") else: print("Failed to submit score") except ValueError: print("Invalid score entered") elif choice == "5": # Create new profile - simplified for demo name = input("Enter new profile name: ").strip() if not name: print("Name cannot be empty") continue success = integration.register_new_user(name) if success or not integration.api_enabled: print(f"Profile '{name}' created successfully!") else: print("Failed to create profile") elif choice == "6": print("Goodbye!") break else: print("Invalid choice") except KeyboardInterrupt: print("\\nGoodbye!") break except Exception as e: print(f"Error: {e}") if __name__ == "__main__": main()