Here's a detailed README.md
file for your project:
This project automatically posts the top story from Hacker News to a Mastodon account once a day.
- Python 3.9 or higher (for running without Docker).
- Docker (optional, for Docker usage).
- A Mastodon account.
To use this script, you need an access token from Mastodon. Follow these steps to get it:
- Log in to your Mastodon account.
- Go to Settings > Development > New Application.
- Create an application.
- Application name:
HackerNewsPoster
(or any name you prefer). - Redirect URI:
urn:ietf:wg:oauth:2.0:oob
. - Scopes:
write
.
- Application name:
- Submit to create the application.
- Copy the access token provided.
- Clone or download this repository to your local machine.
- Install the necessary Python libraries:
pip install requests mastodon.py
-
Create a Dockerfile in the project directory with the following content:
FROM python:3.9-slim WORKDIR /app COPY . /app RUN pip install requests mastodon.py CMD ["python", "./hn_to_mastodon.py"]
-
Build the Docker image:
docker build -t hn_to_mastodon .
-
Run the Docker container:
docker run --env MASTODON_ACCESS_TOKEN=YOUR_MASTODON_ACCESS_TOKEN hn_to_mastodon
- Set up your environment as described in Environment Setup.
- Run the script:
python hn_to_mastodon.py
To automate the script to run once a day:
- Open your terminal and enter
crontab -e
. - Add the following line to schedule the job (example for 9 AM daily):
0 9 * * * /usr/bin/docker run --env MASTODON_ACCESS_TOKEN=YOUR_MASTODON_ACCESS_TOKEN hn_to_mastodon
- Save and close the editor.
This project is open source and available under the MIT License.
Remember to replace YOUR_MASTODON_ACCESS_TOKEN
with the actual token you obtained from Mastodon. This README.md
provides a comprehensive guide for setting up and running the project, both with and without Docker.