Checking "Star Wars - The Force Awakens" tickets availability with Azure WebJobs, scriptcs and SendGrid
This user story is quite simple: there is a guy (me) who likes Star Wars. This guy wants to buy the best tickets available in an IMAX Cinema. The premiere was not so long ago, so a day after the showtimes are updated, the best seats are booked. This guy (also me) is quite lazy, so he doesn’t like to check the showtimes manually.
Hm… let’s do it like pro developers using cutting-edge technologies!
How the booking system works?There is this whole UI for selecting seats and so on, however there is one interesting request which I can use to check showtimes. It look like this:
POST http://www.cinema-city.pl/scheduleInfoRows HTTP/1.1 Host: www.cinema-city.pl Connection: keep-alive Content-Length: 52 Accept: */* Origin: http://www.cinema-city.pl X-Requested-With: XMLHttpRequest User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36 Content-Type: application/x-www-form-urlencoded Referer: http://www.cinema-city.pl/imax Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.8 Cookie: bla bla bla locationId=1010304&date=09%2F01%2F2016&venueTypeId=2
When there is a picture show on that date it returns an HTML table with links for booking, otherwise an empty HTML table.
scriptcs to make the job doneI’ve written a simple scriptcs which will make a POST with appropriate headers and check if a HTML link opening tag is in the response. If that’s the case, I send an email using fresh, free SendGrid account.
- create a new SendGrid account
- download scriptcs as zip (link) and unzip it to a folder StarWarsCheck
- save the code as checkmovie.csx to folder StarWarsCheck
- update checkmovie.csx with your SendGrid credentials
- add reference to Sendgrid dll’s by invoking scriptcs.exe -Install Sendgrid
- now you can run the script locally. In a console write: scriptcs.exe checkmovie.csx
Note: of course, once showtimes are updated, I will get email every hour. But that’s good, isn’t it? There is a chance I won’t miss it.
Create an Azure WebJob to run scriptcs file every hour
call scriptcs.exe checkmovie.csx
Next, pack whole StarWarsCheck folder as a zip file and upload it as Azure WebJob. Instructions are here.