Skip to content

Harshith1702/leetcode-discord-reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 LeetCode Discord Reporter

Automatically tracks your daily LeetCode grind and posts it to Discord, every night, no PC needed.

GitHub Actions LeetCode Discord Python Cron License


πŸ“– Table of Contents


πŸš€ What It Does

Every day at 10:15 PM IST, this bot wakes up on GitHub's servers and:

  • βœ… Fetches all LeetCode problems you solved that day
  • πŸ“¬ Posts them directly to your Discord channel
  • πŸ’€ Requires zero input from you, PC can be completely off

Example Discord Message

Today (3 problems):
1) https://leetcode.com/problems/find-unique-binary-string
2) https://leetcode.com/problems/find-the-smallest-balanced-index
3) https://leetcode.com/problems/minimum-operations-to-sort-a-string

If you didn't solve anything, it posts: No problems solved today


How It Works

cron-job.org (10:15 PM IST)
        β”‚
        β–Ό
GitHub Actions triggered via API
        β”‚
        β–Ό
send.py runs on GitHub's servers
        β”‚
        β–Ό
LeetCode GraphQL API queried
(authenticated with session cookies)
        β”‚
        β–Ό
Accepted submissions from last 16 hours filtered
        β”‚
        β–Ό
Discord Webhook β†’ message posted

Why session cookies? LeetCode blocks unauthenticated requests from cloud server IPs (like GitHub's). Using your browser session cookies authenticates the request and bypasses this block.

Why cron-job.org? GitHub Actions' built-in cron scheduler can delay by up to 60 minutes on free accounts. cron-job.org triggers the workflow via GitHub's API at the exact time every night.


πŸ“Έ Screenshots

Discord Message

Discord Message


⏰ Tracking Window

The bot captures problems solved between 6:15 AM β†’ 10:15 PM IST daily.

Late night solves (after 10:15 PM) won't be included, keeping your daily log clean and honest.


Setup Guide

Step 1 β€” Get Your LeetCode Cookies

Your cookies authenticate the request so GitHub's servers aren't blocked by LeetCode.

  1. Go to leetcode.com and log in
  2. Press F12 β†’ Application tab β†’ Cookies β†’ https://leetcode.com
  3. Find and copy these two values:
    • LEETCODE_SESSION
    • csrftoken

Step 2 β€” Create a Discord Webhook

  1. Open your Discord server β†’ right-click your channel β†’ Edit Channel
  2. Go to Integrations β†’ Webhooks β†’ New Webhook
  3. Give it a name (e.g. LeetCode Bot) and copy the webhook URL

Step 3 β€” Add GitHub Secrets

Go to your repo β†’ Settings β†’ Secrets and variables β†’ Actions β†’ New repository secret

Secret Value
LEETCODE_USERNAME Your LeetCode username
LEETCODE_SESSION Cookie from Step 1
LEETCODE_CSRF csrftoken from Step 1
DISCORD_WEBHOOK Webhook URL from Step 2

Step 4 β€” Push the Code

Push the code to your repo. Then continue to Step 5 for reliable timing.

Step 5 β€” Set Up cron-job.org (For Reliable Timing)

GitHub Actions cron can delay by up to 1 hour. Use cron-job.org to trigger it exactly on time.

  1. Sign up free at cron-job.org
  2. Create a new cronjob with:
    • URL: https://api.github.com/repos/YOUR_USERNAME/leetcode-discord-reporter/actions/workflows/YOUR_WORKFLOW_ID/dispatches
    • Schedule: 10:15 PM IST (16:45 UTC)
    • Method: POST
    • Headers:
      • Authorization β†’ token YOUR_GITHUB_TOKEN
      • Accept β†’ application/vnd.github.v3+json
    • Body: {"ref":"main"}
  3. Save and test

⚠️ To get your Workflow ID, open this URL in your browser: https://api.github.com/repos/YOUR_USERNAME/leetcode-discord-reporter/actions/workflows

Step 6 β€” Done πŸŽ‰

Your bot will now post every night automatically. No PC needed.


πŸ“ Project Structure

leetcode-discord-reporter/
β”œβ”€β”€ assets/
β”‚   └── discord-screenshot.png   # Discord bot output preview
β”œβ”€β”€ send.py                    # Core script β€” fetches & posts submissions
β”œβ”€β”€ LICENSE                    # MIT License
β”œβ”€β”€ README.md                  # This file
└── .github/
    └── workflows/
        └── daily.yml          # Triggered by cron-job.org every night at 10:15 PM IST

πŸ”§ Customization

Change the posting time

Update the schedule in your cron-job.org dashboard to your preferred time.

Change the tracking window

Edit send.py:

if now - sub_time < timedelta(hours=16):  # tracks from 6:15 AM IST

Increase or decrease the hours as needed.

Change the number of submissions fetched

Edit the limit in send.py:

"variables": {"username": username, "limit": 10}

Increase if you solve more than 10 problems a day.


πŸ”„ Cookie Refresh (Every ~2 Weeks)

LeetCode session cookies expire. When the bot stops working:

  1. Log in to leetcode.com β†’ F12 β†’ Application β†’ Cookies
  2. Copy fresh LEETCODE_SESSION and csrftoken values
  3. Update them in GitHub β†’ Settings β†’ Secrets

πŸ› Troubleshooting

Problem Cause Fix
No problems solved today but you did solve Cookies expired Refresh LEETCODE_SESSION and csrftoken in GitHub Secrets
KeyError: LEETCODE_SESSION Secret not added to yaml env Add secret name to env block in daily.yml

❓ FAQ

Q: Does my PC need to be on? No. Everything runs on GitHub's servers triggered by cron-job.org.

Q: Will it work if I don't solve anything? Yes. It posts No problems solved today so you still get a daily reminder.

Q: How long do cookies last? Around 2 weeks. You'll need to refresh them when the bot stops working.

Q: Can I use this for Codeforces too? Not currently. Only LeetCode is supported.

Q: Is my data safe? Yes. All sensitive values are stored as GitHub Secrets and never exposed in code or logs.

Q: What if I solve more than 10 problems in a day? Increase the limit value in send.py from 10 to a higher number.


🀝 Contributing

Contributions are welcome! If you have ideas to improve this:

  1. Fork the repo
  2. Create a new branch: git checkout -b feature/your-feature
  3. Make your changes
  4. Commit: git commit -m "Add your feature"
  5. Push: git push origin feature/your-feature
  6. Open a Pull Request

Ideas for contribution

  • Add Codeforces support
  • Add problem difficulty in the Discord message
  • Add weekly summary report
  • Add streak tracking

πŸ”’ Security Notes

  • βœ… All sensitive values are stored as GitHub Secrets, never in code
  • ⚠️ If your Discord webhook URL leaks, regenerate it immediately: Discord β†’ Channel Settings β†’ Integrations β†’ Webhooks β†’ Regenerate URL
  • ⚠️ Never commit cookies directly into your repo
  • ⚠️ Never share your GitHub Personal Access Token publicly

πŸ’‘ Inspiration

In class one day, our sir mentioned a student from another campus who had built something really cool, a bot that sent daily solved problem links to the college Discord server with a single command. Sir was genuinely impressed, said he only found out about it a few days later.

That story stayed with me. I took that same idea and pushed it a step further, no button, no local PC. Mine just runs automatically every night at 10:15 PM and posts on its own, whether my PC is on or not.

Respect to that guy for the inspiration. πŸ™


Built with πŸ’ͺ ig, to keep the grind accountable...

About

Automatically posts your daily LeetCode solved problems to Discord every night, no PC needed.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages