Extending @CocktailsBot with interactive commands

Twitter bot that posts cocktails every hour

Pulling, formatting and publishing a cocktail recipe every few hours is fine, but somewhat limited. It serves well enough as a source of inspiration when you have no idea what to make, but what if you need the recipe of a particular cocktail at a particular moment? Or even better, what if you’re craving a cocktail based on that one ingredient you have at home?

With the excuse of @CocktailsBot surpassing 300 followers and 1000 tweets, I decided to extend its functionality by adding a couple of interactive commands:

  • Make me something with <ingredient>.
  • Make me a <cocktail>.

The goal of this is enabling users to actively affect the bot’s behavior, and turn it into a dual-channel mean of communication instead of a mere emitter. With these new features, every time a Twitter user mentions @CocktailsBot with one of these two patterns, the bot will parse and interpret the query, try to satisfy it, and answer accordingly.

After all, if drinking is a social activity, my bot should also be able to socialize 🙂

Continue reading “Extending @CocktailsBot with interactive commands”

Writing a Chrome Extension to extract CSS paths faster

How to write a Chrome Extension to extract CSS paths

In the last months I have been playing with a lot of projects that involve scraping data from websites. No matter whether you’re filling databases with data from online reviews or coding a Twitter that posts abstract GIFs hourly, at some point you will need to lookup the CSS paths of the web elements you want to scrape or interact with.

Both Chrome’s and Firefox’s Dev Tools include a function to do this: right-clicking any element of the DOM tree displays a Copy selector option that saves the element’s path into the clipboard.

Of course, to do this it’s necessary to (1) open the Dev Tools, which takes 2 clicks, (2) select an element of the page, (3) right-click the element on the tree and (4) hit the Copy selector option, taking a total of 5 clicks. This may not seem like a big deal, but once you’ve implemented a few scraping projects it becomes obvious that this mechanical task is actually quite unconvenient and time-wasting.

Continue reading “Writing a Chrome Extension to extract CSS paths faster”

Implementing a bot that tweets beautifully formatted cocktail recipes

Twitter bot that publishes cocktail recipes

I have always been a big fan of mixology, which is the science of mixing and composing drinks in a way that they deliver the best experience to the palate.

In the past, when I have wanted to make new cocktails, I had to pull recipes from websites like Liquor. As my passion for this alternative contemporary form of art increased, I wanted to find a way to contribute a little grain of sand of my own to it.

This is how I came up with the idea behind @CocktailsBot, a Twitter bot that posts a cocktail recipe every 6 hours.

This way, any Twitter user with a passion similar to mine, could wake up to a recipe for a cocktail delivered right in the comfort of their Twitter feed.

I wanted to make the bot present the information in the most comfortable and accessible way, I decided to implement the following features:

  • Every recipe would be formed of two or more tweets. The main tweet would display the ingredients, and answer(s) to that tweet would describe the instructions.
  • The ingredients of the cocktail would be preceded by a related emoji.
  • An image with the final result would be included.
Continue reading “Implementing a bot that tweets beautifully formatted cocktail recipes”

Porting @concinnus to Instagram

Instagram bot that posts abstract gifs

Roughly one year after building @concinnus for Twitter, I decided it would be a good idea to implement a port for Instagram. I have never been a big fan of the latter, but it is difficult to deny that, of all networks, it’s probably the best target for publishing the kind of content Concinnus publishes — abstract GIFs.

Besides, I had never had the chance to play with the Instagram API, so it seemed like a good opportunity to also learn something new.

Since I already had the core logic of the bot implemented, it seemed like the task would reduce to adding a new channel of distribution. However, as soon as I started experimenting, the following limitations started to show:

  • Instagram only allows to upload images and videos, but not GIFs.
  • Converting GIFs to videos required the use of CPU-intensive tools that my Bluehost shared-hosting plan did not support or allow.
  • No good libraries for Instagram existed for Python 2.7, which I was forced to use on the shared hosting.

With this, it became obvious that I would have to find a workaround for these limitations, and execute the Instagram bot in a server with higher performance.

I contracted the cheapest VPS I could find (offered by OVH), and I set up the basic tools I normally use (Python, pip, etc). 

Continue reading “Porting @concinnus to Instagram”

Tweeting periodic bits of inspiration using Selenium

Selenium based Twitter bot

At this point, I had already acquired some experience on scraping content online. However, the method followed with @concinnus was quite rudimentary compared to the industry standards, and I was excited to get to play with more robust solutions like Selenium.

In the past, when in need of visual inspiration, I have always resorted to Pinterest. While I have much appreciation for this network, it is not my social media of choice, and having an application/bookmark/favorite for it only to satisfy this use case didn’t seem very reasonable. Instead, I realized I could take steps to integrate this into the social network I use on a regular basis: Twitter.

That’s how I came up with the idea behind @HourlyDesign, a bot that posts a little piece of design every hour, with the intention of introducing some visual inspiration in the Twitter feed.

My first idea was to pull images from Pinterest itself, but it seemed to defy the purpose of the project, so I quickly discarded it. Instead, I realized that sites like Dribbble, Behance and many others are packed with interesting and inspiring content by and for designers.

On top of this, these websites feature the most popular content at the moment in a specific section, which is much more convenient than browsing the vast sea of noise that predominates on Pinterest (and certainly easier to automate).

Continue reading “Tweeting periodic bits of inspiration using Selenium”

Notes on making a Twitter bot that posts abstract GIFs

Twitter bot for abstract gifs

For years, I have followed and been fascinated with Archillect, the 1-million-followers Twitter bot coded by Murat Pak that posts interesting pictures every 20 minutes. The bot, which relies on artificial intelligence (as the author explains here), is based on a pool of Tumblr keywords that grows as the tweets posted receive feedback.

This way, Archillect learns from the tastes of the followers, and caters its decision-making process depending on the reactions of the users. And, oh, it works like a charm. I used to like Archillect’s “taste” so much, that I once took the time to extract 75,000+ of its posted images to use them as a slideshow screensaver.

After a while following it and enjoying its posts, Archillect strongly inspired me to try and create my own Twitter bot. Implementing something as complex seemed a little bit risky for the first time, so I decided I would leave out of my bot the feedback-learning aspect, but I was set on making it post content that other people would find as enjoyable as I find Archillect’s.

Continue reading “Notes on making a Twitter bot that posts abstract GIFs”