CLI tool to post LeetCode solutions as GitHub gists and X threads
Project description
LeetCode X (Twitter) Thread Poster
Automatically post your daily LeetCode solutions to X as a threaded learning journal!
Example
Like this thread - posts your daily coding progress with links to your GitHub Gists.
Features
- Automatic day counter
- Creates a continuous thread on X
- Write solutions in your editor
- Automatically creates Github Gists
- Tracks your progress
- Links to your detailed Gist writeups
- Simple command-line interface
Setup Instructions
Step 1: Prerequisites
- Python 3.10 or higher
- X (Twitter) account
- GitHub account
- uv recommended
Step 2: Clone/Download This Project
git clone https://github.com/plainsight16/lc-thread-posts.git
cd lc-thread-posts
Step 3: Install Dependencies
uv venv
source .venv/bin/activate
Step 4: Install the project
uv pip install -e
This also registers the CLI command:
leetcode-post
Step 5: Get X API Credentials
5.1: Apply for X Developer Account
- Go to https://developer.twitter.com
- Click "Sign up" or "Sign in"
- Click "Apply for a developer account"
- Choose "Hobbyist" → "Making a bot"
- Fill out the application form:
- What will you use the X API for?
"I want to create a bot that automatically posts my daily coding practice solutions to X as a learning journal. Each day, I solve algorithm problems on LeetCode to improve my programming skills and share my solutions with detailed explanations on GitHub Gist. My bot will post these solutions as a thread to track my progress and help other learners."
- What will you use the X API for?
- Accept terms and verify your email
- Wait for approval (usually instant to a few hours)
5.2: Create an App
Once approved:
- Go to https://developer.twitter.com/en/portal/dashboard
- Click "+ Create Project"
- Project Name: "LeetCode Poster" (or any name)
- Use Case: "Making a bot"
- Project Description: "Posts my daily coding solutions"
- Click "Next"
- App Name: "leetcode-bot-yourname" (must be unique)
- Copy and save your API Key, API Secret, and Bearer Token immediately!
5.3: Set Up Authentication
- Click on your app name
- Go to "Settings" tab
- Scroll to "User authentication settings"
- Click "Set up"
- Configure:
- App permissions: Select "Read and Write"
- Type of App: Select "Web App, Automated App or Bot"
- Callback URI:
http://localhost:3000 - Website URL:
https://github.com(or your website)
- Click "Save"
5.4: Generate Access Tokens
- Go to "Keys and tokens" tab
- Under "Access Token and Secret", click "Generate"
- Copy and save your Access Token and Access Token Secret
You should now have:
- API Key
- API Secret Key
- Bearer Token
- Access Token
- Access Token Secret
Step 6: Get Github API Credentials
- Go to settings on your github profile menu
- Select Developer settings
- Select Personal Access tokens
- Then Fine-grained tokens
- Add permissions for managing gists
Step 7: Configure Environment Variables
-
Copy the example file:
cp .env.example .env
-
Open
.envin a text editor -
Fill in your credentials (remove the placeholder text):
TWITTER_API_KEY=your_actual_api_key_here TWITTER_API_SECRET=your_actual_api_secret_here TWITTER_ACCESS_TOKEN=your_actual_access_token_here TWITTER_ACCESS_TOKEN_SECRET=your_actual_access_token_secret_here TWITTER_BEARER_TOKEN=your_actual_bearer_token_here GITHUB_TOKEN=your_actual_github_token -
Save the file
IMPORTANT: Never commit or share your .env file. It contains your API credentials.
Usage
Daily Workflow
- Solve a LeetCode problem
- Run
leetcode-post post <problem-name> - Confirm and post
First Time Setup
If this is your first post, run:
leetcode-post start-thread
This posts your introduction tweet and initializes the thread.
Gist Format
Create your Gist at https://gist.github.com with this structure:
# Problem Name
[Question Link](https://leetcode.com/problems/...)
## Approach
Explain your approach here...
## Implementation
```python
class Solution:
def problemName(self, params):
# Your code here
pass
Results
Runtime: X ms (Beats Y%) Memory: X MB (Beats Y%)
Complexity
- Time: O(n)
- Space: O(1)
Project Structure
```text
lc-thread-posts/
├── pyproject.toml
├── README.md
├── .env.example
├── .venv/
│
└── leetcode_post/
├── __init__.py
├── cli.py
├── twitter.py
├── gist.py
├── editor.py
├── progress.py
└── templates.py
Troubleshooting
Error: "pip is not recognized"
python -m pip install -r requirements.txt
Error: "401 Unauthorized"
- Ensure app has "Read and Write" permissions in X Developer Portal
- Regenerate Access Token and Access Token Secret
- Update
.envwith new credentials
Error: "Module not found: imghdr"
python -m pip install --upgrade tweepy
Test your credentials:
python test_credentials.py
Start a new thread:
Delete progress.json and run the script again.
How It Works
The script maintains a progress.json file that tracks:
- Current day number
- Thread ID (your first tweet)
This ensures all posts are connected in one continuous thread.
Customization
Edit the tweet format in post_leetcode.py:
# Default format
tweet_text = f"Day {day}\n\n{problem_name}\n\n{gist_url}"
# Add hashtags
tweet_text = f"Day {day}\n\n{problem_name}\n\n{gist_url}\n\n#LeetCode #100DaysOfCode"
Contributing
Contributions are welcome! Feel free to:
- Report bugs
- Suggest features
- Submit pull requests
Important Notes
Rate Limits
Twitter Free tier limits:
- 1,500 tweets per month
- 50 tweets per day
For daily posting, you're well within limits!
Privacy
- Your
.envfile contains sensitive credentials - Never commit it to GitHub
- Never share it with anyone
- The
.gitignoreprotects it automatically
Best Practices
- Backup your
progress.jsonoccasionally - Keep your credentials secure
- Test with a test tweet first
- Check Twitter's automation rules: https://help.twitter.com/en/rules-and-policies/twitter-automation
Support
For issues:
- Check the troubleshooting section
- Verify your
.envcredentials - Ensure app has "Read and Write" permissions
- Open an issue on GitHub
License
MIT License
Acknowledgments
Inspired by @Ifihan_'s daily LeetCode thread.
Resources:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file leetcode_post-0.1.0.tar.gz.
File metadata
- Download URL: leetcode_post-0.1.0.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fee3a981e58b4c862f9241e3c8c11eea15bcfe43a3804e521e2ac7df8ea48ae6
|
|
| MD5 |
a70063225cb03509d59ec8191d602338
|
|
| BLAKE2b-256 |
c52c74bc4297fe5a1f85e6680a04da47618aa5971b52b21977224ad16af130b5
|
File details
Details for the file leetcode_post-0.1.0-py3-none-any.whl.
File metadata
- Download URL: leetcode_post-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc612f0ab738b91ec2c9e83ca55eb16bfb7fe5046fb4d978bab9f8b48e7ee0eb
|
|
| MD5 |
a41e08948181c4decd6b43d62e24aed1
|
|
| BLAKE2b-256 |
3e939b136a5206b668ed2f34329db3cad7c0fe3377a1a58c9003e3d1d4da69d8
|