This Python bot automatically plays the "Higher or Lower" game specifically for the Anime category on https://www.higherorlowergame.com/anime/score/.
It uses Selenium to interact with the web browser, fetches anime score data from the Jikan API (api.jikan.moe), caches scores locally in an SQLite database to minimize API calls, and employs fuzzy string matching to find the most accurate anime entry when dealing with potentially ambiguous titles returned by the game vs. the API. It also considers the type (TV, Movie, OVA, etc.) provided by the game to further refine the search.
- Automated Gameplay: Opens the game website and automatically clicks "Higher" or "Lower" based on fetched scores.
- Jikan API Integration: Fetches anime scores from the Jikan v4 API.
- Local Score Caching: Stores fetched scores in a local SQLite database (
data/anime_scores.db) to avoid redundant API calls and respect rate limits. - Fuzzy Title Matching: Uses
thefuzzlibrary to find the best match between the game's title and the API results, handling variations in naming (e.g., seasons, subtitles). - Type Matching: Uses the Type (TV/Movie) shown in the game to improve the accuracy of the API result selection.
- Session Statistics: Tracks and logs the number of rounds played, the highest score achieved during the session, and the total runtime to
testsResults.txt. - Error Handling: Includes basic error handling for browser interaction and API requests.
-
Prerequisites:
- Python 3.x installed.
- A compatible web browser (e.g., Chrome, Firefox) installed.
- The corresponding WebDriver for your browser (e.g.,
chromedriver,geckodriver).
-
Clone the Repository (if applicable):
git clone <your-repository-url> cd <repository-directory>
-
Install Dependencies:
- It's highly recommended to use a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
- Install the required Python packages:
pip install -r requirements.txt
- It's highly recommended to use a virtual environment:
-
WebDriver Setup:
- Download the WebDriver executable that matches your browser version.
- Place the WebDriver executable in the
drivers/directory within the project folder (create the directory if it doesn't exist). The bot currently expectschromedriver.exeorgeckodriver.exein this location (seehandlers/browser_handler.py). You might need to adjust the path inbrowser_handler.pyif you place it elsewhere or use a different driver.
- Ensure your WebDriver is correctly set up in the
drivers/directory. - Activate your virtual environment (if you created one).
- Run the main script from the root project directory:
python main.py
The bot will open a browser window, navigate to the game, and start playing automatically. Progress and results will be printed to the console. Session results will be appended to testsResults.txt.
ROUND_DELAY: (inmain.py) Sets the delay in seconds between rounds to allow the page to load. Default is 8 seconds.DB_PATH: (inhandlers/database_handler.py) Path to the SQLite database file. Default isdata/anime_scores.db.RESULTS_FILE: (inmain.py) Path to the file where session results are logged. Default istestsResults.txt.JIKAN_API_*Constants: (inhandlers/jikan_api.py) Base URL, request delay, search limit, and similarity threshold for the Jikan API interaction.
.
├── .gitignore
├── main.py # Main script to run the bot
├── requirements.txt # Python dependencies
├── testsResults.txt # Log file for test/run results
├── data/ # Directory for data files
│ └── anime_scores.db # SQLite database for caching scores (auto-generated)
├── drivers/ # Directory for WebDriver executables (add your driver here)
│ └── ... # (e.g., chromedriver.exe, geckodriver.exe)
├── handlers/ # Directory for modular handler scripts
│ ├── __init__.py
│ ├── browser_handler.py # Handles Selenium browser setup and interaction
│ ├── database_handler.py # Handles SQLite database operations
│ ├── game_logic.py # Handles game-specific element finding and actions
│ └── jikan_api.py # Handles Jikan API communication and matching
└── venv/ # Virtual environment (if used)
selenium: For browser automation.requests: For making HTTP requests to the Jikan API.thefuzz[speedup]: For fuzzy string matching (requirespython-Levenshteinfor speedup).
See requirements.txt for specific versions.