Skip to content

Instantly share code, notes, and snippets.

@sankalp-khare
Created July 18, 2012 03:22
Show Gist options
  • Save sankalp-khare/3133963 to your computer and use it in GitHub Desktop.
Save sankalp-khare/3133963 to your computer and use it in GitHub Desktop.
Bookmyshow Checker for Prasadz IMAX
#!/usr/bin/env python
# Author : Sankalp Khare
# Date : [2012-07-12 Thu]
# Pass the movie id (can be easily found on bookmyshow) to this script plus a
# date, and it will run in a loop, checking if bookings for the said movie are
# open on the given date. If yes, it will notify you of the same via
# notify-send
# e.g. The Dark Knight Rises : ET00010030 , Date (YYYYDDMM) : 20120720
# TODO : Add option to check all days of the coming week and notify
# accordingly
import urllib
import sys
import notify2
import time
import re
from BeautifulSoup import BeautifulSoup
from optparse import OptionParser
def movieName(ID):
p = urllib.urlopen('http://in.bookmyshow.com/movies/nowshowing/')
content = p.read()
p.close()
movieList = re.findall(r'var arrMov = \[(\[.*?\])\]',content)[0]
movieListArray = re.findall(r'\[([^\]]*?)\]',movieList)
for item in movieListArray:
details = item.split(",")
if details[0].strip('"') == ID:
return details[1].strip('"')
# Variables to be used in Parser Object Initialization
desc = "BookMyShow Movie Bookings checker. Pass the Movie ID and Date, and it will notify you when bookings have opened. Currently only for Prasadz IMAX. Author: Sankalp Khare | sankalp.khare@gmail.com"
# Cinema IDs and other stuff : http://in.bookmyshow.com/cinemas/
# Initialize Parser
parser = OptionParser(description=desc)
# Add Parser Options
parser.add_option("-i","--id",
dest="ID",
help="Movie ID (e.g. ET00010030)",
metavar="ID")
parser.add_option("-d","--date",
dest="DATE",
help="Date. YYYYDDMM",
metavar="DATE")
# Parse
(options,args) = parser.parse_args()
# Exit with help message if Mandatory argument not passed
if not options.ID or not options.DATE:
parser.print_help()
sys.exit(1)
try:
dayObject = time.strptime(options.DATE,'%Y%m%d')
dayString = time.strftime("%a, %d %b %Y",dayObject)
except ValueError:
print "Invalid Date"
parser.print_help()
sys.exit(1)
# Set some variables
divID = "div"+options.ID
URL = "http://in.bookmyshow.com/cinemas/Prasads-IMAX-Screen/PRHY/"+options.DATE
movie = movieName(options.ID)
# print URL
# print divID
while True:
# Fetch the page
pageFile = urllib.urlopen(URL)
pageHtml = pageFile.read()
pageFile.close()
# Soup it!
soup = BeautifulSoup("".join(pageHtml))
# Search for the required div
results = soup.findAll("div", {"class":"dslcm", "id":divID})
if results:
# Initialize Notifications Lib
notify2.init("BookMyShow Checker")
# Notification Elements
nSummary = "Bookings Open!"
nMessage = "%s\n%s" %(movie,dayString)
# Notification
n = notify2.Notification(nSummary,nMessage,"notification-message-im")
n.show()
time.sleep(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment