bot: Add a little script to post about recent development activity from a handful of RSS feeds I've gathered.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 17m1s

This commit is contained in:
Cory McWilliams 2024-11-09 09:01:34 -05:00
parent 88b25790e8
commit 57257f63dd

55
tools/buttfeed.py Executable file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env python3
import argparse
import feedparser
import json
import time
parser = argparse.ArgumentParser()
parser.add_argument('--state_file', help = 'Path to a file in which to store state.')
args = parser.parse_args()
k_feeds = {
'tildefriends': 'https://dev.tildefriends.net/cory/tildefriends.rss',
'erlbutt': 'https://github.com/cmoid/erlbutt/commits/main.atom',
'habitat': 'https://gitlab.com/quickdudley/habitat/-/commits/main.atom',
'habitat': 'https://gitlab.com/quickdudley/habitat/-/commits/internet.atom',
'manyverse': 'https://gitlab.com/staltz/manyverse/-/commits/master?format=atom',
'ahau': 'https://gitlab.com/ahau/ahau/-/commits/master.atom',
}
def fix_title(entry):
if entry.summary.startswith('<a href=') and '\n' in entry.summary and entry.summary and '\n' in entry.summary:
return entry.summary.split('\n')[1]
return entry.title.split('\n')[0]
def get_entries():
results = []
for name, url in k_feeds.items():
feed = feedparser.parse(url)
for entry in feed.entries:
results.append((time.mktime(entry.get('updated_parsed')), name, entry.link, fix_title(entry)))
results.sort()
results.reverse()
return results
state = {}
if args.state_file:
try:
with open(args.state_file, 'r') as f:
state = json.load(f)
except:
pass
cutoff = state.get('last_update') or (time.time() - 2 * 7 * 24 * 60 * 60)
entries = get_entries()
if entries:
text = '# Recent Secure Scuttlebutt Development Activity\n\n' + '\n'.join([f' * [{entry[1]}] [{entry[3]}]({entry[2]})' for entry in entries if entry[0] > cutoff])
state['last_update'] = entries[0][0]
if args.state_file:
with open(args.state_file, 'w') as f:
json.dump(state, f)
content = json.dumps({'type': 'post', 'text': text, 'mentions': []})
subprocess.check_call(['out/debug/tildefriends', 'publish', '--user', 'cory', '--identity', '@DnYDqFfmxdNkYQlpflF9Wkltk2HIhJ5u1MW5njKPLzM=.ed25519', '--content', content])
else:
print(text)