This project is designed to notify you on Discord about trending GitHub repositories.
Referenced: GitHub Trending
It uses the API from github-trending-api.
Make sure that no other process is using ports 5010 or 5011.
If you want to manage notifications without editing the configuration JSON directly, you can create a Discord bot:
- Go to the Discord Developer Portal
- Create a new application.
- Navigate to the "Bot" section and click "Add Bot."
- Copy the bot token (never share it).
- Go to "OAuth2" → "URL Generator," check the "bot" and "Send Messages" permissions, and then invite the bot to your server.
This script is set up in UTC+1, executing every day at 20:00, every Saturday at 20:00, and on the last day of the month at 20:00.
Below is an example configuration. Update these values in your config.json file:
Create one if needed.
{
"API_URL": "http://localhost:5010/repositories", // Enter the URL of your local API
"DISCORD_WEBHOOK_URL_FOR_DAILY": "<https://discord.com/api/webhooks/for_daily>", // Webhook URL for daily GitHub project notifications
"DISCORD_WEBHOOK_URL_FOR_weekly": "<https://discord.com/api/webhooks/for_weekly>", // Webhook URL for weekly GitHub project notifications
"DISCORD_WEBHOOK_URL_FOR_monthly": "<https://discord.com/api/webhooks/for_monthly>", // Webhook URL for monthly GitHub project notifications
"BOT_TOKEN": "", // Your Discord bot token if you want to manage the webhook easily; otherwise, leave empty.
"language": "" // The default language for filtering repositories; leave empty to include all.
}- Python 3.9+
- Node.js & npm (for the API in
API/github-trending-api) - A Discord account and Bot Token (configured via the Discord Developer Portal)
- Docker (optional, for deploying the application in a container)
- config.json
Update the fileconfig.jsonwith your information:"BOT_TOKEN": Your Discord bot token."DISCORD_WEBHOOK_URL_FOR_DAILY","DISCORD_WEBHOOK_URL_FOR_weekly", and"DISCORD_WEBHOOK_URL_FOR_monthly"as needed."language": Default language to filter trending repositories (optional).
- Python 3.7+ (recommended)
- pip
- git (to clone the repository)
- Node.js and npm (if your GitHub Trending API relies on an npm-based project)
-
Clone the Repository
git clone https://github.com/yourusername/github-trending-project.git cd github-trending-project -
Create a Virtual Environment (Optional but Recommended)
# On Unix-based systems: python -m venv venv source venv/bin/activate # On Windows: python -m venv venv venv\Scripts\activate
-
Install Dependencies
A
requirements.txtshould be provided. If not, install the necessary packages manually:pip install flask discord requests rich schedule click
-
Set Up Node.js (For GitHub Trending API)
If your setup requires the GitHub Trending API to run via
npm start(as referenced inmain.py), ensure Node.js is installed. Then navigate to theAPI/github-trending-apidirectory and run:cd API/github-trending-api npm install npm startThe Flask scheduler will verify and launch this process if it isn't running.
Create or update the config.json file in the root directory with your settings. Below is an example:
{
"BOT_TOKEN": "your_discord_bot_token",
"API_URL": "http://localhost:5011/repositories",
"DISCORD_WEBHOOK_URL_FOR_DAILY": "your_discord_webhook_url_for_daily",
"DISCORD_WEBHOOK_URL_FOR_WEEKLY": "your_discord_webhook_url_for_weekly",
"DISCORD_WEBHOOK_URL_FOR_MONTHLY": "your_discord_webhook_url_for_monthly",
"language": ""
}- BOT_TOKEN: Your Discord bot token.
- API_URL: URL to fetch trending repositories (as provided by your GitHub Trending API).
- DISCORD_WEBHOOK_URL_FOR_*: Webhook URLs for sending Discord messages for the respective periods.
- language: Default programming language filter for trending repositories (leave empty for all).
-
Install Python Dependencies:
pip install -r requirements.txt
-
Install Node.js Dependencies:
cd API/github-trending-api npm install cd ../..
-
Run the Project:
You can start both processes simultaneously using the startup script:
bash start.sh
Alternatively, run
main.pyandbot.pyin separate terminal windows.
-
Build the Docker Image:
docker build -t github-trending-notification . -
Run the Container:
docker run -p 5010:5010 -p 5011:5011 github-trending-notification
- 5010: Port for the Flask API (
/set_languageendpoint). - 5011: Port for the Node.js GitHub Trending API.
- 5010: Port for the Flask API (
-
/display_trending <period> <language>
Displays trending GitHub repositories for the specified period (e.g.,daily) along with an optional language filter.
Example:/display_trending daily python -
/set_language <language>
Changes the default language for trending repositories.
Example:/set_language javascript -
/help
Displays the list of available commands.
- POST
/set_language
Allows you to update the default language in the configuration.- Example JSON Payload:
{ "language": "python" } - The API is accessible at: http://localhost:5010/set_language
- Example JSON Payload:
-
Occupied Ports:
If you encounter errors related to ports (5010 or 5011), ensure they are not being used by another process on your machine or modify the port mappings when launching the Docker container. -
npm Not Found:
The Dockerfile installs Node.js and npm. If running locally and npm is not recognized, ensure it is installed and added to your PATH. -
Discord Responses:
Confirm that your bot responds correctly to interactions by using the asynchronous methods in the Discord API (seebot.pyfor details on handling commands and responses).
Feel free to contribute or adapt this project to your needs!