Leveraging a hidden API to autonomously lookup player data on Super Smash Bros Melee Slippi NetPlay Network using Python
Beautiful Hand-Crafted GUI
100/100 Amazing
Python Script Overview
This Python script is designed to monitor a specified directory for new Super Smash Bros. Melee replay files (SLP files) and dynamically update a graphical user interface (GUI) with player data retrieved from a hidden Slippi API after each game starts. The script comprises several key components and functionalities:
Key Features:
File Monitoring:
Utilizes the watchdog library to detect new SLP files in a specified directory.
Defines a custom event handler, NewFileHandler, that triggers when a new file is created.
Netplay Code Extraction:
Implements the getNetplayCodes function to parse the new SLP file and extract player netplay codes using regular expressions.
The function retries every 5 seconds until the game file is fully written and accessible.
API Requests:
Defines the getPlayerData function to fetch player data from the Slippi API using the extracted netplay codes.
Sends a POST request to the Slippi API endpoint with appropriate headers and JSON data.
Parses the JSON response to extract player details such as display name, ELO rating, and win-loss record.
Rank Calculation:
Implements the get_rank and get_player_ranks functions to determine player ranks based on their ELO ratings.
Defines a mapping of ELO thresholds to rank names (e.g., Bronze, Silver, Gold, etc.).
Includes the get_rank_image and get_player_rank_images functions to associate rank names with corresponding image files.
GUI Updates:
Uses the tkinter library to create a user interface that displays player names, rankings, and rank images.
Defines the update_data function to refresh the GUI labels with the latest player data after each new game.
Configures the main window, including window size, background image, and label positions for displaying player information.
Ensures global references to image objects to prevent garbage collection.
Concurrency:
Runs the directory monitoring in a separate thread using the threading module to keep the GUI responsive.
Utilizes the run_with_retry function to handle exceptions and retry API requests if they fail initially.
Script Execution:
The monitor_directory function sets up the file monitoring, and the run_monitoring function runs this monitoring process in a separate thread.
The startGui function initializes the GUI, creating the main window, setting up labels, and loading images.
The script starts both the directory monitoring and the GUI when executed.
Usage:
To use the script, specify the directory to monitor by setting the directory_to_watch variable. The script will automatically detect new SLP files in this directory, fetch player data from the Slippi API, and update the GUI with the latest player information after each game.