Tweeting a Blog Post via command line

Posted on January 6, 2020 by Riccardo

In the previous post we have seen how to scaffold a blog post with a Haskell script. Today, we are going to automate tweeting.

The heart of the script is the tweet function which uses:

The content of the tweet comes from mkTweet:

Thereโ€™s still one piece missing. We want to pass as input the credentials for Twitter and the path to the blog post we want to tweet about. This is super eazyly done using optparse-applicative. Its readme is awesome, so please refer to that to learn more.

With that in place, calling the script without the mandatory argument gets us:

We can also call it with --help to get a detailed explanation:

Instead, a proper call (e.g. ./tweet.hs posts/ would tweet successfully:

The whole script can be found on Github.