Skip to content

Instantly share code, notes, and snippets.

@scuba323
Created January 4, 2019 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scuba323/4f0d03452731947f7fe96812de4e4e04 to your computer and use it in GitHub Desktop.
Save scuba323/4f0d03452731947f7fe96812de4e4e04 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import requests
from os import environ
# Mastodon information
token = "another32bytehexdump"
postURL = 'https://mastodon.cloud/api/v1/statuses'
# The snowman prefix.
# Currently, Mastodon's website messes up the display of the
# snowman emoji, ⛄️, because the variation selector, U+FE0F,
# appears as a box. This code constructs a string for the snowman
# without the variation selector. It's possible this won't display
# properly on some clients or platforms.
prefix = b'\xe2\x9b\x84'.decode()
# Assemble the toot content.
home = environ['HOME']
lastPostInfo = open(home + '/path/to/all-posts.txt').readlines()[-1]
(date, time, slug, title) = lastPostInfo.split(' ', 3)
title = title.rstrip()
path = date[:-3].replace('-', '/')
leanURL = 'http://leancrew.com/all-this/{}/{}/'.format(path, slug)
toot = '''{} {}
{}'''.format(prefix, title, leanURL)
# Send the toot.
header = {'Authorization': 'Bearer {}'.format(token)}
payload = {'status': toot}
r = requests.post(postURL, data=payload, headers=header)
print(r.json()['uri'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment