Photo: Puppy


One thing I missed severely during Covid-19 Lockdown was petting cats and dogs. Now, I get to pet them again.

Puppy sniffing my fingers as it ran around me

I took this photo as he was running left and right in glee and I am amazed this came out this good.

Programming: Blog post Re-Share Bot


Note: This post is a little bit technical and if I write any follow-ups to this, they will get more technical. I will try to make this as simple as I possibly.

Also note: The Bot is not yet complete


Paid version of WordPress offers the ability to install plugins. I am a free version user of WordPress & I suspect I will always remain a free user.

The one feature that I would like to have in the free version is the ability to re-share my old posts on a social media network and maybe even repost it on my blog. I sometimes feel like my old posts are just gathering dust in the archives and I would like to air them out from time to time. I did spend a lot of time trying to perfect them and if not for them, I wouldn’t still be writing.

There are number of plugins which can be used to re-share old posts automatically on a blog. But I can’t install plugins. Therefore, I decided to write a bot that would run on my machine which would do this for me.


Idea:

I am aware of how much a nuisance bots are on social media these days. I am aware that I want to, I could find something which suits my needs. But I also want to write this thing myself. For the last three years, all I have applications written has been for a paycheck and nothing important for myself.

The idea for this bot is about 1-2 years old. It was around the time that I was frantic about the view count of my blog. I no longer care about the numbers. So in a way, this bot is pretty much useless for me.

Here is a rough framework of this app:

  1. The app would read the list of blog posts from a file and extract the following from each post: Title, Link, Description, Category and two tags.
  2. I would create a database of posts from the above information.
  3. I would start at the oldest and move up the ladder sharing posts.

Implementation:

At the inception, I was learning C++ and I wanted to write a C++ bot. I tried to, but between my inept knowledge and lack of design I couldn’t get started properly.

The second time I tried to do this, I was learning Java & Android. So I figured it won’t be too difficult to run an Android app on my phone and it will automatically share posts without any prompt. Again, I didn’t know Android/Java well enough to do this.

To summarize, I had two issues:

  1. I don’t know the language well enough.
  2. I do not have the algorithm for this bot.

C has been the language I am most familiar with. I am a C programmer with 3+ years experience. Plus, I am C mentor to students on Exercism. I could remove one of the two issues by just using C and working out the chunks of the algorithm. This way if I want an Android app later I have a blueprint of how the bot should structured.

Getting a list of my posts:

If you enter your WordPress URL and add /feed at the end of it, you will receive a RSS file. RSS file for WordPress will only give me 150 posts & I know about RSS feeds are just XML files. It is not the complete blog history that I would like to have but it s good enough.

C, unlike Java, does not come with its own XML libraries. So my first job was to figure out what can I use to read the RSS file.

LibXML2 came in the picture. It is OpenSource and available natively in Ubuntu. With a few commands I had it installed. My experience with it is not great. It does everything you want it to, but it still feels clunky to use. But I stuck with it and I was able to get it working.

Next I needed to actually download the RSS file from WordPress. LibCurl was perfect for his. Working with LibCurl was the easiest experience ever. I am hoping that in the future, I would somehow call Twitter APIs with Curl too. I am not even sure it is possible.

I am currently trying to build up a stable database with the list of posts that I can extract. I don’t know how I am going to post things on Twitter/Reddit or any other media yet.


Check it out on GitHub.