pull down to refresh

HnF BotHnF Bot

A bot that reposts every new ~HealthAndFitness post from Stacker.News to Twitter and Nostr

earlier explanation #999588


FeaturesFeatures

  • RSS Fetching (getRSSItems): Parses the ~HealthAndFitness RSS feed and extracts new items, using <guid> as the canonical post link.
  • Duplicate Prevention (loadPostedCache/savePostedCache): Tracks posted items in posted.txt to avoid reposting the same content.
  • Twitter Posting (postToTwitter): Posts formatted messages to Twitter/X, appending /r/realBitcoinDog to each link and handling API credentials securely.
  • Nostr Posting (postToNostr, https://github.com/axelvyrn/HnFBot/blob/main/hnfPoster.js): Calls a Python subprocess to post to Nostr relays, using the same message format and duplicate prevention.
  • CI/CD & State Persistence: GitHub Actions workflow (.github/workflows/hnfbot.yml) runs the bot on a schedule and persists posted.txt between runs using artifacts.
  • Robust Path Handling: All file and script paths are resolved absolutely for compatibility in local and CI environments.

SetupSetup

PrerequisitesPrerequisites

  • Node.js (v18+ recommended)
  • Python 3.8+
  • Twitter API credentials (developer account)
  • Nostr private key

InstallationInstallation

  1. Clone the repository:
    git clone <repo-url>
    cd HnFBot
  2. Install Node.js dependencies:
    npm install
  3. Install Python dependencies:
    pip install -r requirements.txt
  4. Create a .env file in the project root with the following variables:
    TWITTER_POSTER_API_KEY=your_twitter_api_key
    TWITTER_POSTER_API_KEY_SECRET=your_twitter_api_secret
    TWITTER_POSTER_ACCESS_TOKEN=your_twitter_access_token
    TWITTER_POSTER_ACCESS_TOKEN_SECRET=your_twitter_access_token_secret
    NOSTR_PRIVATE_KEY=your_nostr_private_key

UsageUsage

Local RunLocal Run

node hnfPoster.js

GitHub ActionsGitHub Actions

  • The bot is configured to run via .github/workflows/hnfbot.yml.
  • State is persisted using GitHub Actions artifacts (see workflow file for details).

TroubleshootingTroubleshooting

  • Twitter 401/429 errors:
    • Check that your API credentials are correct and not rate-limited.
    • Twitter developer accounts have strict posting limits (17 posts/day).
  • Nostr errors:
    • Ensure your NOSTR_PRIVATE_KEY is valid and relays are reachable.
  • posted.txt not updating:
    • Make sure the bot has write permissions in the working directory.
  • RSS feed not updating:
    • Check the Stacker.News RSS feed URL and your network connection.

FAQFAQ

Q: Why does the bot use <guid> instead of <link> for posting?
A: <guid> always points to the Stacker.News item, which is the canonical post URL. <link> may point to an external article.

Q: How does the bot avoid duplicate posts?
A: It tracks posted links in posted.txt and skips any already listed.

Q: Can I run the bot on a schedule?
A: Yes, use a cron job or GitHub Actions scheduled workflow.

Q: How do I add more relays for Nostr?
A: Edit the NOSTR_RELAYS list in nostr.py.

Q: How do I rotate API credentials?
A: Update your .env file and GitHub Secrets as needed.


ContributingContributing

  1. Fork the GitHub repository and create a new branch for your feature or bugfix.
  2. Write clear, concise code and add comments where helpful.
  3. Add or update tests if applicable.
  4. Submit a pull request with a detailed description of your changes.
  5. Be respectful and responsive in code reviews.

LicenseLicense

MIT

@deSign_r pointed out a Github Artifact fetch failure in #1001317

Update 1: HnF bot now fetches posted links from a public gist in my github gists and updates the gist then and there

Update 2: The .env file should now include 2 more fields, in case you are forking the repo

GIST_ID = the_gist_id
GIST_TOKEN = your_pat_token_with_gist_scope
reply

this is great, thank you!

Have been playing around with it and I see an error in the actions' annotations:

Annotations
1 error
run
Unable to download artifact(s): Artifact not found for name: posted-txt
        Please ensure that your artifact is not expired and the artifact was uploaded using a compatible version of toolkit/upload-artifact.

Can be fixed smehow?

reply

thank you for pointing this out
i was actually working on this.
the ci doesn't seem to be able to fetch the posted.txt even through github artifacts
i will try a database approach

reply

I had fun cleaning the nostr feed...

reply
reply

So do we have one of these or multiple?

reply

one and only

reply

hope this makes sense now

reply