Skip to content

kaushikgopal/tootbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

mastodon elephant toot empty

Tootbot

Every time I create a new post in this blog I like to toot or tweet about it. Instead of manually doing this, I have my Mac Mini run this shell script on a cron job, which does it automatically for me.

The way it works is pretty simple:

  • Download my latest blog feed as a json file.
  • Check for any new blog posts.
  • Compares with a local CSV file that records previous toots.
  • Posts new toots to Mastodon.

This is used by kau.sh to auto post new blog posts to his Mastodon.

How to run:

This script is written in Kotlin and can be run from anyone's command line

brew install kotlin
kotlin tootbot.main.kts

Script variables:

1. Mastodon instance name

Should be obvious

val mastodonInstance = "mastodon.social"
//val mastodonInstance = "hachyderm.io"

2. Mastodon Token

Head on over to your Mastodon Profile -> Developer settings page and create an application. After creating a new application you should find "Your access token".

// Settings page link:
  // https://mastodon.social/settings/applications
  // https://hachyderm.io/settings/applications
val mastodonToken = "BUXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_AAAAAA"

3. Json feed url

Your blog should make available a json feed which the script will automatically download and parse for new blog posts. If you use Hugo my blog theme Henry has a template you can use.

val jsonFeedUrl = "https://your-blog/feed.json"

4. Previously tooted

After posting a toot to Mastodon, this script will write the status to a CSV file locally called "toots.csv". It simply jots a map of your blog post id and the Mastodon status number.

It additionally also uses this file to prevent duplicate tooting of the same blog post. So remember to not clear this file, if you've started using this script.

val tootsFile = "./toots.csv".toPath()

5. Force a toot

There are times I want to forcefully toot a blog post that otherwise wouldn't get picked up by the script (e.g. a blog post posted before today). For these cases I like adding the blog post id in this variable, which will make sure to toot the blog post anyway.

val forceToot = listOf(
    "blog/2023-02-02-own-your-online-presence/index.md",
)

How I use it:

For now, I run this script on a cron job from command line, on a Mac mini server that I use. I could dockerize it and make it even more easy but this works for me and is pretty simple, so no current plans for that.

SCR-20230203-qiz

About

๐Ÿ˜ auto-toot bot to Mastodon. Parses a Json blog feed and posts to Mastodon saving status to a csv file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages