Guest User

Untitled

a guest
Apr 20th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.90 KB | None | 0 0
  1. import requests
  2. import bs4
  3. import time
  4. import smtplib
  5. import os
  6. import socket
  7. import sys
  8. import os
  9. from pygame import mixer
  10. #from gi.repository import Notify
  11. from email.mime.text import MIMEText
  12. from email.mime.image import MIMEImage
  13. from email.mime.multipart import MIMEMultipart
  14.  
  15.  
  16. def send_mail(data):
  17.     username = 'bookplus12@gmail.com'
  18.     password = 'gap5246256'
  19.     msg = MIMEMultipart()
  20.     text = MIMEText(data)
  21.     msg['Subject'] = 'ALERT FROM BOOK MY SHOW'
  22.     msg.attach(text)
  23.     to_addr = 'akhil6030@gmail.com'
  24.     server = smtplib.SMTP('smtp.gmail.com:587')
  25.     server.ehlo()
  26.     server.starttls()
  27.     server.ehlo()
  28.     server.login(username, password)
  29.     server.sendmail(username, to_addr, msg.as_string())
  30.     server.quit()
  31.     print('Mail Sent')
  32.  
  33.  
  34. def notify_me(to_send):
  35.     print("--------------tickets are available at -----------------------\n" +
  36.           to_send)
  37.     #  Notify.init("Book My Show")
  38.     #  Notify.Notification.new('available at '+to_send).show()
  39.     send_mail("---------------tickets are available at -----------" + to_send)
  40.     to_send = ''
  41.     # mixer.init()
  42.     # mixer.music.load("C:\\Users\\akhil\\Desktop\\web\\Loud_Alarm_Clock_Buzzer-Muk1984-493547174.mp3")
  43.     # mixer.music.play()
  44.     # time.sleep(70)
  45.     # mixer.music.stop()
  46.  
  47.  
  48. alllist = []
  49. allstr = ""
  50. to_send = ''
  51. num_prev_th = 0
  52. prethi = set()
  53. while 'Cinepolis: Manjeera Mall, Kukatpally' not in to_send or 'Prasads: Large Screen' not in to_send or 'PVR Forum Sujana Mall: Kukatpally, Hyderabad' not in to_send or 'PVR: Inorbit, Cyberabad' not in to_send or 'AMB Cinemas: Gachibowli' not in to_send:
  54.  
  55.     # proxies  = {'http': 'http://akhil3060:map5246256@10.10.10.3:3128/',
  56.     #            'https': 'https://akhil3060:map5246256@10.10.10.3:3128/'
  57.     #            }
  58.     # request = requests.get('https://in.bookmyshow.com/buytickets/captain-marvel-hyderabad/movie-hyd-ET00097168-MT/20190308', proxies=proxies)
  59.     request = requests.get(
  60.         'https://in.bookmyshow.com/buytickets/avengers-endgame-hyderabad/movie-hyd-ET00100559-MT/20190426'
  61.     )
  62.     print("status =",request.status_code)
  63.     if request.status_code == 200:
  64.         parser = bs4.BeautifulSoup(request.text, "html.parser")
  65.         li = parser.select(
  66.             'div[class="__name "] > a[class="__venue-name"] > strong')
  67.         length = len(li)
  68.         # print("firsty li \n",li)
  69.         # print("numb prev len ", allstr)
  70.         if num_prev_th < length:
  71.             # print(" after numb prev len ", allstr)
  72.             mymsg = "\n\n\n This is Book my show Assistant: Now tickets are available in new theater \n =====" + allstr
  73.             send_mail(mymsg)
  74.         if num_prev_th != length:
  75.             num_prev_th = length
  76.         print(
  77.             "=========================STARTED HERE=================================\n"
  78.         )
  79.         print("\nNumber of theatres available " + str(len(li)))
  80.         # print("\n -----------------------New theaters are--------------------------- \n")
  81.  
  82.         # print("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n")
  83.         # print("diff ",prethi.difference(set(li)))
  84.         # for gg in prethi.difference(set(li)):
  85.         #     print("gg ",gg)
  86.         #     if gg == '':
  87.         #         print("No new theaters are available")
  88.         #     else:
  89.         #         print("this is the difference")
  90.         #         print(gg)
  91.         #         print("diff ends here")
  92.         #         # notify_me(gg)
  93.         #         send_mail("I am sendinfg the difference",gg)
  94.         # print(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n")
  95.         print(
  96.             "---------------------------All theaters -------------------------------\n"
  97.         )
  98.  
  99.         r = map(lambda x: x.getText() + "\n", li)
  100.         # print(type(r) , list(r))
  101.         alllist = []
  102.         allstr = ""
  103.         for i, j in enumerate(r):
  104.             print(i + 1, ":", j)
  105.             allstr += j[:-2] + "\n"
  106.             alllist.append(j[:-2])
  107.         # print(alllist)
  108.         for i in li:
  109.             if 'Cinepolis: Manjeera Mall, Kukatpally' == i.getText(
  110.             ) or 'Prasads: Large Screen' == i.getText(
  111.             ) or 'PVR Forum Sujana Mall: Kukatpally, Hyderabad' == i.getText(
  112.             ) or 'PVR: Inorbit, Cyberabad' == i.getText(
  113.             ) or 'AMB Cinemas: Gachibowli' == i.getText():
  114.                 to_send += i.getText() + "\n"
  115.         prethi = set(li)
  116.         # print("prethi ===",prethi)
  117.     else:
  118.         print(
  119.             "movie isn't available at the city you entered... I guess that the reason... Have a nice day.."
  120.         )
  121.         break
  122.  
  123.     if to_send == '':
  124.         print(
  125.             " -----------  Selected theaters are not ready yet-------------------------------\n"
  126.         )
  127.         # send_mail("hello no ready \n"+ allstr)
  128.     else:
  129.         # print(to_send)
  130.         notify_me(to_send)
  131.  
  132.     time.sleep(20)
Add Comment
Please, Sign In to add comment