Avatar Ilya Mateyko

go.astrophena.name/tools Module

GitHub repository | Commit (90b6d01)

Personal tools.

tgfeed

Tgfeed fetches RSS feeds and sends new articles via Telegram.

Usage

$ tgfeed [flags...]

Environment Variables

The tgfeed program relies on the following environment variables:

Configuration

tgfeed loads it's configuration from config.star file on GitHub Gist. This file is written in Starlark language and defines a list of feeds, for example:

feeds = [
    feed(
        url = "https://hnrss.org/newest",
        title = "Hacker News: Newest",
        block_rule = lambda item: "pdf" in item.title.lower(), # Block PDF files.
    )
]

Each feed can have a title, URL, and optional block and keep rules.

Block and keep rules are Starlark functions that take a feed item as an argument and return a boolean value. If a block rule returns true, the item is not sent to Telegram. If a keep rule returns true, the item is sent to Telegram; otherwise, it is not.

The feed item passed to block_rule and keep_rule is a struct with the following keys:

Special Feeds

tgfeed supports special feed URLs for integrating with services other than traditional RSS/Atom feeds.

You can use the special URL tgfeed://github-notifications as a feed URL to receive your GitHub notifications via Telegram and mark them as read on GitHub. This requires a GitHub personal access token with the notifications scope, which should be provided via the GITHUB_TOKEN environment variable.

State

tgfeed stores it's state on GitHub Gist.

It maintains a state for each feed, including last modified time, last updated time, ETag, error count, and last error message. It keeps track of failing feeds and disables them after a certain threshold of consecutive failures. State information is stored and updated in the state.json file on GitHub Gist. You won't need to touch this file at all, except from very rare cases.

Stats Collection

tgfeed collects and reports stats about every run to Google Sheets. You can specify the ID of the spreadsheet via the STATS_SPREADSHEET_ID environment variable. To collect stats, you must provide the SERVICE_ACCOUNT_KEY environment variable with JSON string representing the service account key for accessing the Google API. Stats include:

You can use these stats to monitor performance of tgfeed and understand which feeds are causing problems.

Administration

To edit the config.star file, you can use the -edit flag. This will open the file in your default editor (specified by the $EDITOR environment variable). After you save the changes and close the editor, the updated config.star will be saved back to the Gist. For example:

$ tgfeed -edit

To reenable a failing feed that has been disabled due to consecutive failures, you can use the -reenable flag followed by the URL of the feed. For example:

$ tgfeed -reenable https://example.com/feed

To view the list of feeds, you can use the -feeds flag. This will also print the URLs of feeds that have encountered errors during fetching. For example:

$ tgfeed -feeds