JI
jibla/hacker-news-bot
Dead simple bot, that fetches latest news from hacker news API and posts in Discord or Slack channel using webhooks.
Hacker News Bot
This is a simple Python script for a Discord and Slack bot, designed to fetch the latest news from Hacker News (HN) and post it to a specified Discord/Slack channel via webhooks. The bot is optimized for Docker deployment, offers different data storages (local files or SQLite) to track which news stories have been posted.
How It Works
- Fetches the top X news stories, from Hacker News top stories API, at a regular interval.
- Checks against a stored list of already-posted stories, individually for Discord and Slack and if a story is not in the list, it is considered new, otherwise, bot tries to find next new story.
- Post these new stories to the Discord/Slack channel linked through the provided webhook URL.
Running Locally
To run the bot locally, you will need either Python directly or Docker for containerized deployment.
Running with Docker
docker run
-e DISCORD_WEBHOOK_URL="your_webhook_url_here"
-e SLACK_WEBHOOK_URL="your_webhook_url_here"
-e SCHEDULE_PERIOD=60
-e FETCH_TOP_STORIES_AMOUNT=5
-e STORAGE=local
jibla/hn-botEnvironment Variables
DISCORD_WEBHOOK_URL: The webhook URL for the Discord channel where news will be posted.SLACK_WEBHOOK_URL: The webhook URL for the Slack channel where news will be posted.SCHEDULE_PERIOD: The frequency (in minutes) at which the bot fetches and posts news.FETCH_TOP_STORIES_AMOUNT: The number of top stories the bot should fetch and attempt to post at each interval.STORAGE: Specifies the method for tracking posted stories (localfor file storage,databasefor SQLite).
You can also build it from source using the Dockerfile:
docker build -t hn-bot .Running with Python
- Install Dependencies:
pip install requests schedule sqlite3- Set the required environment variables in your terminal:
export DISCORD_WEBHOOK_URL="your_webhook_url_here"
export SLACK_WEBHOOK_URL="your_webhook_url_here"
export SCHEDULE_PERIOD=60
export FETCH_TOP_STORIES_AMOUNT=5
export STORAGE=local # Or 'database'- Run the script:
python hn_bot.pyOn this page
Languages
Python95.6%Dockerfile4.4%
Contributors
Latest Release
alphaMarch 29, 2024Created March 28, 2024
Updated February 10, 2026