An automated bot that solves LeetCode problems using GPT-4 and browser automation. Built with Python, Playwright, and AgentQL.
- Automated login to LeetCode
- Random problem selection
- Intelligent solution generation using GPT-4
- Automatic code submission
- Persistent login state management
- Detailed logging system
- Python 3.12+
- Poetry for dependency management
- OpenAI API key
- AgentQL API key
- LeetCode account
- Clone the repository:
git clone https://github.com/yourusername/leetcode-solver.git
cd leetcode-solver- Install dependencies using Poetry:
poetry install- Install Playwright browsers:
poetry run playwright install- Create a
.envfile based on.env.example:
cp .env.example .env- Add your API keys to
.env:
OPENAI_API_KEY=your_openai_api_key
AGENTQL_API_KEY=your_agentql_api_key
LEETCODE_USERNAME=your_leetcode_username
LEETCODE_PASSWORD=your_leetcode_password
Run the bot with Poetry:
poetry run python src/bot.py [number_of_problems]The number_of_problems argument is optional and defaults to 1.
src/bot.py- Main entry pointutils/- Utility functionslogin.py- LeetCode login handlingselect_random.py- Random problem selectionsolve_problem.py- Problem solving logic
logs/- Log files directory.env- Environment variablesleetcode_login.json- Persistent login state
playwright- Browser automationagentql- Web scraping and element selectionopenai- GPT-4 API integrationpython-dotenv- Environment variable managementblack- Code formatting
This project is licensed under the GNU General Public License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- The bot uses GPT-4 for solution generation, which requires an OpenAI API key with GPT-4 access
- Solutions are formatted with 4-space indentation
- Login state is saved to avoid repeated logins
- Detailed logs are saved in the
logsdirectory