mcornick.com source
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
901 B

import csv
import io
import re
import requests
import subprocess
def toot_most_recent(section, include_text=False):
subprocess.check_output(['hugo'])
stream = io.StringIO(subprocess.run(
['hugo', 'list', 'all'], stdout=subprocess.PIPE
).stdout.decode('utf-8'))
posts = [p for p in csv.DictReader(stream) if re.match(
r'^content/{}'.format(section),
p['path']
)]
last_post = sorted(posts, key=lambda p: p['date'])[-1]
status = "{}: {}".format(last_post['title'], last_post['permalink'])
if include_text:
text = ''.join(open(last_post['path']).readlines()[7:])
status += '\n\n{}'.format(text)
token = open('usercred.secret').read().strip()
url = 'https://tilde.zone/api/v1/statuses'
auth = {'Authorization': 'Bearer {}'.format(token)}
params = {'status': status}
requests.post(url, data=params, headers=auth)