visit
On 26th April 2019, the most hyped and most anticipated movie of our generation was released Avengers Endgame, and I managed to grab the best seats in the hall for the first day first show in IMAX, Bangalore.
When the release date for the movie was announced, I found out that I had booked a flight to go home in the evening for the exact same day three months ago. Living in Bangalore, with the airport being almost 3hrs away I knew that If I’m not able to get the tickets for the morning show, the movie I was waiting for almost a year will most probably get spoiled & I won’t be able to view it in IMAX which I was dying for. I was in a tough spot, this is a city where you need to book tickets at least 3–4 days in advance for the weekends, and with the added hype around Avengers, something had to be done. My friends and I would be regularly refreshing , a popular event ticket booking portal so that we don’t miss out on the tickets, but I knew this strategy would never work. The only solution was to automate this somehow, write a script that periodically refreshes the site and when the tickets are available to alert us in a way that we don’t miss it.So every movie which is coming soon on bookmyshow gets a page of its own, for every city it is different. For Avengers Endgame for Bangalore, it was this
Screenshot from bookmyshow.com portal
The only difference was it didn’t have the Book Tickets button at the time when it was still in the coming soon phase. So all I needed to do was periodically load the page and check when it finally gets the button element. The shell script for it was pretty simple.
# curl the bookmyshow website
output=`curl -s //in.bookmyshow.com/bengaluru/movies/avengers-endgame/ET00090482 | grep -c 'Book Tickets'`
if [ $output -gt 0 ]
then
# Alert somehow, will come to that later
fi
To periodically run it, I had to run the script as a . But adding it in my own machine meant I had to keep it on at all times which wasn’t feasible. I needed to add this cron job in some remote server which will keep running no matter what. So I added it in a remote AWS server that I had provisioned for testing. You can refer to the first part of my other in case you need to provision an ec2 AWS instance for yourself. And I added the below crontab entry
# Run the alert_ticket script every minute as a scheduled cron
*/1 * * * * sh /home/ec2-user/check_ticket.sh
#!/usr/bin/python
from twilio.rest import Client
# Your Account SID from twilio.com/console
account_sid = "xxxx"
# Your Auth Token from twilio.com/console
auth_token = "xxxx"
client = Client(account_sid, auth_token)
message = client.messages.create(
to="+xxxxxxxxxxxx",
from_="+zzzzzzzzzzzz",
body="Book Tickets for avengers endgame")
call = client.calls.create(
to="+yyyyyyyyyyyy",
from_="+zzzzzzzzzzzz",
url="//handler.twilio.com/twiml/xxxx")
# Send message
print(message.sid)
# Trigger a call
print(call.sid)
And my check_ticket.sh script changed to calling the above script when it figures out the tickets are available.
# Curl the bookmyshow website
output=`curl -s //in.bookmyshow.com/bengaluru/movies/avengers-endgame/ET00090482 | grep -c 'Book Tickets'`
if [ $output -gt 0 ]
then
/usr/bin/python /home/ec2-user/alert_by_twilio.sh
fi