Writing a generative contemporary art bot for Instagram

Photo by Steve Johnson on Unsplash

I like contemporary art and I am pretty good at coding fancy stuff as well

Code Generated Images

I am a minimalist, so I didn’t want to pollute my piece using too many elements like I did in the past. The simplest idea that came to my mind was to generate random colored square images, that could be easily uploaded on any social network platform.

…I know what you are thinking, I could have used machine learning algos and many other interesting technologies but I had just one free afternoon to make it so I decided to keep it really simple and effective…

After a couple of hours I already had my online golang microservice running, providing a super simple API to generate random images like the following one:

Social Media

Once the image generator microservice was ready I had to decide on which platform I would upload these images.

Twitter has already plenty of bots and its API is really developer friendly so this time I decided to use Instagram instead because by design it’s better suited to show generated images than its more text-based competitors.

I created an account called the_colour_of_the_day with the intent of uploading a generated image a day. Unfortunately I realized pretty soon that the Instagram REST API doesn’t allow bots (besides the fact that the documentation is really overcomplicated).

…at this point I opted for the plan B “the hacker way”…

Image Uploader

Uploading an image on Instagram via web without using their app is not that easy. However, I figured out that identifying my browser as an iOS device, I could publish them from the web ui. Being already familiar with puppeteer and javascript, I wrote a simple upload script. As an example, let’s check the first steps to let my chromium instance log in via node js:

puppeteer Instagram login

After 30 minutes I was able to automate the whole uploading process, letting computers doing what they could best: simplify my life.

At the moment, my script can download the generated colored image, detect its main color, give it a name (thanks also to this great library made by my friend David), add custom tags to the post and publish it to Instagram.

Scheduled Updates

I want the_colour_of_the_day bot could post one colored image a day for as long as possible, generating a wall of different colors as a contemporary art piece. Of course I didn’t want to do it manually so the last piece of this puzzle was scheduling these daily uploads.Luckily the Github Actions provide already all I needed out of the box:

Conclusion

I had a lot of fun working with golang and making something a bit fancier than my everyday programming tasks.

I am really curious to see if the_colour_of_the_day will remain online for enough time to become a de facto “post-contemporary art” piece. This is how the current profile page looks like:

the_colour_of_the_day Instagram account

Some Credits

Many thanks to my friends nirazul and meodai for all the help they gave me correcting my poor English on this article ❤️

I code stuff for living — Riot.js Maintainer — I like javascript, haskell and golang

I code stuff for living — Riot.js Maintainer — I like javascript, haskell and golang