Pils & Programming - Join the social club

We code, we laugh, we hangout. Welcome.

These words are inscribed in many a Pils & Programming event description. Indeed they are the quintessential description of the Pils & Programming events.

For those of you not familiar with Pils & Programming it is a recurring event where people who share an interest in programming and other facets of information technologies and computer sciences can come together to code socially and have food, drink, and conversation.

Pils & Programming was originally born when Torstein Thune and Nils Norman Haukås decided they wanted to code socially around three years ago and it is still going strong. Where Pils & Programming started with an emphasis on sharing one's programming work in a social arena, it has later evolved into a space where it is possible to relax after a hard week of studies or work. In its heyday Pils & Programming could attract upwards of 30 happy programmers, but it has lately seen a smaller crowd. One reason might be the lack of Facebook events, and we will try to improve on this moving forward. In fact we have an event for tomorrows Pils & Programming right here!

Unfortunately we rely on Facebook to host events, much so because our main audience is reachable there. One issue with recurring events on Facebook is the need to manually create them. Facebook's graph API does not do event creation and there is no way to set up recurring events on the website. Because I'm supposedly a Research and Development fellow at Kompiler I've tried to improve how we create events to make the process less painful. But how do we do this? If we could just make some code that could tell the browser to log into Facebook and create the event for us. Well, that is just what I did.

You might have heard about Selenium which is a tool to automate browsers. It is often used for end to end front-end testing and has a number of libraries/drivers for different programming languages. Because I've grown somewhat comfortable with Node.js (serverside JavaScript) I used WebDriver.io. It has simple functions to do HTML DOM element lookup using pretty standard CSS selectors, and can send simple events to the browser such as key presses and click events. Additionally each function returns a Promise so that the code running browser interaction can be flattened out.

My first rough and very hacky attempt looks like this:

The script imports necessary libraries and defines some options. I won't go into details about them. Then the script defines the event details text and date = moment().weekday(5).format('l'); determines the date string to use for the event by finding the date of Friday the current week and formatting it in Facebook's expected US date format (who thinks MM/DD/YY is a good idea anyway?).

The last block of code simply does a Promise-chain of function calls that performs a series of browser interactions. Essentially it tells webdriver.io to tell Selenium to:

  • visit the Facebook group's site
  • provide username
  • provide password
  • click login
  • click on events link
  • click create event button
  • set values in each event input field
  • click create button

Each function uses a standard css selector to find an element. This approach is probably not very robust and I foresee the eventual markup change that will break the Selenium process. In fact this setup might be broken already. The script did work for this Friday's event with the exception of the time input-field (which requires some special treatment it appears). I also did not implement functionality to add an event cover photo as that would probably be a bit much work.

If you want to try the script out you need to have the Selenium web driver installed and running in the background. You also need firefox on your path. See the Webdriver.io Developer Guide for more info.

Your steadfast R&D guy,
Snorre.