Skip to main content

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

  1. Go to https://developer.twitter.com
  2. Click "Sign up" or "Sign in"
  3. Click "Apply for a developer account"
  4. Choose "Hobbyist""Making a bot"
  5. 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."

  6. Accept terms and verify your email
  7. Wait for approval (usually instant to a few hours)

5.2: Create an App

Once approved:

  1. Go to https://developer.twitter.com/en/portal/dashboard
  2. Click "+ Create Project"
  3. Project Name: "LeetCode Poster" (or any name)
  4. Use Case: "Making a bot"
  5. Project Description: "Posts my daily coding solutions"
  6. Click "Next"
  7. App Name: "leetcode-bot-yourname" (must be unique)
  8. Copy and save your API Key, API Secret, and Bearer Token immediately!

5.3: Set Up Authentication

  1. Click on your app name
  2. Go to "Settings" tab
  3. Scroll to "User authentication settings"
  4. Click "Set up"
  5. 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)
  6. Click "Save"

5.4: Generate Access Tokens

  1. Go to "Keys and tokens" tab
  2. Under "Access Token and Secret", click "Generate"
  3. 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

  1. Copy the example file:

    cp .env.example .env
    
  2. Open .env in a text editor

  3. 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
    
  4. Save the file

IMPORTANT: Never commit or share your .env file. It contains your API credentials.


Usage

Daily Workflow

  1. Solve a LeetCode problem
  2. Run leetcode-post post <problem-name>
  3. 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

Screenshot

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 .env with 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 .env file contains sensitive credentials
  • Never commit it to GitHub
  • Never share it with anyone
  • The .gitignore protects it automatically

Best Practices

  1. Backup your progress.json occasionally
  2. Keep your credentials secure
  3. Test with a test tweet first
  4. Check Twitter's automation rules: https://help.twitter.com/en/rules-and-policies/twitter-automation

Support

For issues:

  1. Check the troubleshooting section
  2. Verify your .env credentials
  3. Ensure app has "Read and Write" permissions
  4. Open an issue on GitHub

License

MIT License


Acknowledgments

Inspired by @Ifihan_'s daily LeetCode thread.


Resources:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leetcode_post-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leetcode_post-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

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

Hashes for leetcode_post-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fee3a981e58b4c862f9241e3c8c11eea15bcfe43a3804e521e2ac7df8ea48ae6
MD5 a70063225cb03509d59ec8191d602338
BLAKE2b-256 c52c74bc4297fe5a1f85e6680a04da47618aa5971b52b21977224ad16af130b5

See more details on using hashes here.

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

Hashes for leetcode_post-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cc612f0ab738b91ec2c9e83ca55eb16bfb7fe5046fb4d978bab9f8b48e7ee0eb
MD5 a41e08948181c4decd6b43d62e24aed1
BLAKE2b-256 3e939b136a5206b668ed2f34329db3cad7c0fe3377a1a58c9003e3d1d4da69d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page