Skip to content

Commit

Permalink
Merge pull request #299 from barrucadu/nya/rss-summary
Browse files Browse the repository at this point in the history
[nyarlathotep] Use summary for kjp-to-hacksrus, not title
  • Loading branch information
barrucadu authored Sep 6, 2024
2 parents 76fcf7e + 58b7c78 commit 9924ae6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion hosts/nyarlathotep/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,11 @@ in
startAt = "hourly";
serviceConfig = {
ExecStart =
let python = pkgs.python3.withPackages (ps: [ ps.docopt ps.feedparser ps.requests ]);
let python = pkgs.python3.withPackages (ps: [ ps.beautifulsoup4 ps.docopt ps.feedparser ps.requests ]);
in concatStringsSep " " [
"${python}/bin/python3"
(pkgs.writeText "rss-to-mastodon.py" (fileContents ./jobs/rss-to-mastodon.py))
"--use-summary"
"-d https://hacksrus.xyz/"
"-f https://kingjamesprogramming.tumblr.com/rss"
"-l /persist/var/lib/rss-to-mastodon/kjp-hacksrus.txt"
Expand Down
9 changes: 7 additions & 2 deletions hosts/nyarlathotep/jobs/rss-to-mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
Requires the API_KEY environment variable to be set.
Usage:
rss-to-mastodon [--dry-run] -d <domain> -f <feed-url> -l <history-file> [-e <entries>] [-v <visibility>]
rss-to-mastodon [--dry-run] [--use-summary] -d <domain> -f <feed-url> -l <history-file> [-e <entries>] [-v <visibility>]
Options:
--dry-run just print what would be published
--use-summary use the (de-HTMLised) sumamry field, rather than the title
-d <domain> api domain
-f <feed-url> rss feed URL
-l <history-file> file to log feed item IDs to (to prevent double-posting)
-e <entries> maximum number of entries to post [default: 1]
-v <visibility> visibility of entries [default: public]
"""

import bs4
import docopt
import feedparser
import html.parser
Expand All @@ -28,6 +30,7 @@

args = docopt.docopt(__doc__)
dry_run = args["--dry-run"]
use_summary = args["--use-summary"]
api_domain = args["-d"]
feed_url = args["-f"]
history_file = pathlib.Path(args["-l"])
Expand Down Expand Up @@ -64,9 +67,11 @@

# if there are multiple items, post the older ones first
for item in reversed(items):
# handle entities
title = html.parser.unescape(item["title"])

if use_summary:
title = bs4.BeautifulSoup(item["summary"], "html.parser").get_text().strip()

print(item["id"])
print(title)
print()
Expand Down

0 comments on commit 9924ae6

Please sign in to comment.