Last active
January 4, 2018 18:46
-
-
Save jkotra/3b95ee2a94055fdaa28ebfc870a10845 to your computer and use it in GitHub Desktop.
bookmyshow bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import datetime | |
import time | |
import argparse | |
import smtplib | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--silent', help="No print.", action="store_true") | |
args = parser.parse_args() | |
Agnyaathavaasi = "ET00061620" # Example movie | |
DATE_DAY = '10' | |
DATE_MONTH = '01' | |
DATE_YEAR = '2018' | |
DATE = DATE_YEAR + DATE_MONTH + DATE_DAY | |
Divider = '___________________________' | |
url = "https://in.bookmyshow.com/pwa/api/de/showtimes/byevent" | |
querystring = {"regionCode": "HYD", "subCode": "", "eventCode": Agnyaathavaasi, "dateCode": DATE} # HYD = City | |
headers = { | |
'Content-Type': "application/json", | |
'Cache-Control': "no-cache", | |
'Postman-Token': "1315faff-9b41-3e8b-4bf9-7bee28ce9965" | |
} | |
def parse(): | |
global b | |
response = requests.request("GET", url, headers=headers, params=querystring) | |
a = response.text | |
b = json.loads(a) | |
def sendmsg(message): | |
server = smtplib.SMTP('smtp.gmail.com', 587) | |
server.starttls() | |
server.login("USER", "PASS") | |
msg = message | |
server.sendmail("USER", "TOADDR", msg) | |
server.quit() | |
# print(len(b)) | |
# print(b['BookMyShow']['ShowDetails'][0]['Venues'][0]['VenueName']) | |
VenueIndex = [] | |
TargetIndex = [] | |
Target = 'Dilsukhnagar' # Exaple venue/preferred location | |
while True: | |
parse() | |
for i in range(100): | |
try: | |
venue = b['BookMyShow']['ShowDetails'][0]['Venues'][i]['VenueName'] | |
if args.silent is not True: | |
print(venue) | |
if venue not in VenueIndex: | |
VenueIndex.append(venue) | |
except IndexError: | |
print(Divider) | |
print("Total {0} theaters found as of {1}.".format(str(i), str(datetime.datetime.now()))) | |
# target | |
for venue in VenueIndex: | |
if Target in venue: | |
if venue not in TargetIndex: | |
TargetIndex.append(venue) | |
target_detected = '\nTarget venue - {} - is available![BookMyShow BOT]'.format(venue) | |
print(target_detected) | |
sendmsg(target_detected) | |
print(Divider) | |
time.sleep(300) # 300sec = 5min. | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment