Created
January 4, 2019 00:58
-
-
Save scuba323/4f0d03452731947f7fe96812de4e4e04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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