hnmastodonbot (0.1.dev1+gd04d03116)
Published 2026-01-09 13:32:16 +00:00 by cperrin
Installation
pip install --index-url hnmastodonbotAbout this package
Reposts the top posts from news.ycombinator.com to mastodon
HNMastodonBot
A simple bot that fetches top stories from Hacker News and posts them to Mastodon.
Features
- Fetches top stories from Hacker News at regular intervals. The number of stories is configurable (default is 10).
- Posts the story title and URL to Mastodon.
- Automatically posts a reply with a link to the Hacker News comments.
- Tracks posted stories to avoid duplicates.
- Supports Docker deployment.
Requirements
- Python 3.10+
- uv (recommended) or pip
Configuration
The bot is configured using environment variables. Secret values can also be provided via files by appending _FILE to the environment variable name.
| Environment Variable | Description |
|---|---|
MASTODON_INSTANCE_URL |
The base URL of your Mastodon instance (e.g., https://mastodon.social). |
MASTODON_ACCESS_TOKEN |
Access token for the Mastodon account. |
MASTODON_COMMENTS_ACCESS_TOKEN |
Access token for posting comments (can be the same as above). |
TRACKING_FILE |
(Optional) Path to the file where posted story IDs are stored. Defaults to tracking.pkl. |
HASHTAG_CONFIG |
(Optional) Path to the JSON file containing hashtag mappings. Defaults to hashtags.json. |
TOP_STORIES_LIMIT |
(Optional) The number of top stories to consider. Defaults to 10. |
Usage
Command Line Arguments
--dry-run: Simulate actions without posting to Mastodon or updating the tracking file.--limit: Set the number of top stories to consider. OverridesTOP_STORIES_LIMITenvironment variable.
Local Execution
Using uv:
export MASTODON_INSTANCE_URL="https://your.instance"
export MASTODON_ACCESS_TOKEN="your_token"
export MASTODON_COMMENTS_ACCESS_TOKEN="your_token"
uv run main.py
Docker
You can build and run the bot using Docker:
docker build -t hnmastodonbot .
docker run -e MASTODON_INSTANCE_URL="..." \
-e MASTODON_ACCESS_TOKEN="..." \
-e MASTODON_COMMENTS_ACCESS_TOKEN="..." \
hnmastodonbot
Requirements
Requires Python: >=3.10
Details
2026-01-09 13:32:16 +00:00
Assets (2)
Versions (24)
View all
PyPI
1
33 KiB
0.1.dev1+g891d2d022
2026-01-31
0.1.dev1+gc6edda100
2026-01-28
0.1.dev1+g216829957
2026-01-14
0.1.dev1+g6e8408754
2026-01-09
0.1.dev1+g3c6e258c1
2026-01-09