About a week ago, I discovered that Ryanair have a little advertised but otherwise freely accessible API for checking their air fares, and that it comes with a number of useful endpoints. Now, given how good Python is as a language for manipulating textual data, and how easy it is to grab information off the internet, I got to thinking… wouldn’t it be good if I could check all of Ryanair’s fares, automatically, every ten minutes, and filter to only see those from airports near me below a certain price, within a certain date range? Yes, that would be very useful… so I started by taking a look at the way the data is returned from the API calls, in order to understand how I would hook in, and how I’d pull the relevant data back.
Straight away, it was obvious that the script I was going to write would need two fundamental abilities: the ability to reach out and grab the data, and then the ability to interpret the data and extract the relevant fields. To do this, I needed to import two Python modules: urllib2 to grab the data, and json to interpret it. I quickly also discovered that in order to create dates based on a time difference (e.g. the next seven days, the next month), I’d also need the datetime module to use the timedelta class. Surprisingly, having never actually done something with JSON data feeds in Python before, I found that pretty quickly (within less than an hour) I was able to bring back some rudimentary results, and that I had brought into the world (like some proud new father) version 1.0 of Shamrock Disco. At the moment, it’s quite manual in the sense that you must alter config settings within the file to set up your results preferences, and it also currently only looks at single tickets. Plans for future development involve the following:
- Use of argparse or another means by which config settings can be passed as arguments to the script
- Ability to process single and return journeys within a single script
- Ability to process more than one origin airport per script execution
- Ability to provide alerts via SMS or Twitter when user rules met (e.g. Tweet when a flight to Prague costs less than £10)
- Log data output over time to identify averages fares for a given route and hourly, daily, weekly, price trends.
As my experience dealing with these free data feeds grows, I’ll be looking for other projects of interest… specifically where use of automation and web scraping can either save money or, better yet, inform decisions that allow me to make money! Try it yourself… Python is a language with a very gentle learning curve and endless online documentation.