-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathendScript.py
99 lines (82 loc) · 3.21 KB
/
endScript.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
exception_string = "Trying to Install required module: "
try:
import requests
except ImportError:
print(exception_string + "requests\n")
os.system('python -m pip install requests')
try:
from bs4 import BeautifulSoup
except ImportError:
print(exception_string + "BeautifulSoup\n")
os.system('python -m pip install beautifulsoup4')
import requests
from bs4 import BeautifulSoup
import re
import smtplib
import ssl
import configparser
import sys
def sendmail(mail_ids, sender_email_parameter, email_password_parameter, custom_message=None, date_parameter='Date'):
port = 465 # For SSL
smtp_server = "smtp.gmail.com"
sender_email_parameter = sender_email_parameter
receiver_email = mail_ids
password = email_password_parameter
message = """\
Subject: WE ARE IN THE ENDGAME NOW
Hi User,
Hurry up!!! Avengers Endgame IMAX 3D Tickets are now available on """ + date_parameter + """
Thanks & Regards,
Mr Crawler"""
if custom_message:
message = custom_message
context = ssl.create_default_context()
with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
server.login(sender_email_parameter, password)
for email in receiver_email:
server.sendmail(sender_email_parameter, email, message)
while True:
try:
config = configparser.ConfigParser()
config.read('params.ini')
website = 'https://paytm.com/movies/' + config['parameters']['city']
dates = config['parameters']['dates'].split(',')
movie_name = config['parameters']['movie'].lower()
theatre_name = config['parameters']['theatre'].lower()
send_email = config['parameters']['sendmail'].lower()
sender_email = config['parameters']['senderEmail']
email_password = config['parameters']['emailPassword']
mailIds = config['parameters']['mailIds'].split(',')
page = requests.get(website)
soup = BeautifulSoup(page.text, 'html.parser')
soup = soup.find("div", {"id": "popular-movies"})
movies_list = soup.find_all("li")
res = None
for movie in movies_list:
if movie_name in str(movie).lower():
res = str(movie)
break
if res is None:
print('Movie not available')
# os._exit(1)
if res is not None:
for date in dates:
res1 = 'https://paytm.com' + re.search('href=\"(.*?)\?', res).group(1) + '?fromdate=' + date
page2 = requests.get(res1)
soup2 = BeautifulSoup(page2.text, 'html.parser')
showtime_list = soup2.find_all('div', class_='SbzU')
if theatre_name in str(showtime_list[0]).lower():
if send_email == 'yes':
sendmail(mailIds, sender_email, email_password, date_parameter=str(date))
print('Success')
# os._exit(0)
else:
print('Not available')
# os._exit(1)
except:
print('Some exception occured')
sendmail(['[email protected]'], custom_message='Exception Occurred')
print(sys.exc_info()[0])
else:
break