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.

31 lines
1.1 KiB

import csv
import io
import re
import subprocess
import urllib.parse
import urllib.request
def toot_most_recent(section, include_text=False):
stream = io.StringIO(["hugo", "list", "all"], stdout=subprocess.PIPE).stdout.decode(
posts = [
for p in csv.DictReader(stream)
if re.match(r"^{}/".format(section), p["permalink"])
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 = ""
auth = {"Authorization": "Bearer {}".format(token)}
params = urllib.parse.urlencode({"status": status}).encode("ascii")
request = urllib.request.Request(url, data=params, headers=auth, method="POST")