Microblogging with twtxt on Neocities

10/02/19

Last modified on 10/02/19

Categories: Development Tags: Neocities

~/contents

I decided I wanted to add a microblogging component to my website. Originally I started looking around for Hugo themes, but I couldn’t find quite what I was looking for, and I didn’t necessarily want to take the time to update the current theme to accomodate notes or microblog posts when I wasn’t sure if I’d use the feature.

Looking for static microblog generators I rediscovered twtxt, which I kicked around a bit a few years ago on a previous iteration of the site. Having all the tweets in a single text file is really appealing to me, as is the decentralized nature of twtxt in general. Let’s try it!

pip3 install twtxt

Generate config and twtxt file using

twtxt quickstart

twtxt config file allows you to use pre_tweet_hook or post_tweet_hook to run a command before or after tweeting, which allows you to push your file to a remote server. I have posted an example of using the Neocities Python API to update my main site. I created something similar for this.

#! python3
import neocities
USERNAME = "username"
PASSWORD = "password"
TWTXT = "twtxt.txt"

nc = neocities.NeoCities(USERNAME, PASSWORD)
nc.upload((TWTXT,"twtxt.txt"))
print("Uploaded twtxt.")
> python C:\Hugo\Sites\twtxt\tweet_push.py

I had a devil of a time figuring out how to get twtxt to accept this command line however. Last time I ended up doing a workaround where I actually ran a python script that ran twtxt as a subprocess, I think. Well, I wasn’t willing to do that this time. I tried every escape and variation I could think of to no avail. twtxt recognizes a path is being given but dislikes the syntax.

post_tweet_hook = "python 'C:/Hugo/Sites/twtxt/tweet_push.py'"
post_tweet_hook = "python 'C:////Hugo//Sites//twtxt//tweet_push.py'"

I decided to look at the twtxt code itself. Unfortunately I didn’t understand the post_tweet_hook function enough to know what about my path was wrong. Additionally, since twtxt was an executable rather than a library it wasn’t immediately obvious to me how to change post_tweet_hook so it would just run my script. I studied the shlex Python module but still wasn’t sure what the problem was beyond that it may be an issue with Windows and shlex.split.

I looked into alternative methods of uploading to Neocities. I had issues with curl not accepting https. I had issues with the CLI Ruby gem not installing (and I vaguely seem to remember having this problem a while back, too.) So that’s it, for now. Maybe I’ll figure something out down the road.

https://github.com/buckket/twtxt
http://twtxt.xyz/
https://stackoverflow.com/questions/33560364/python-windows-parsing-command-lines-with-shlex
https://stackoverflow.com/questions/4830874/making-shlex-split-respect-unc-paths