Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2015
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. import datetime
  2. import time
  3. import smtplib
  4. from email.mime.multipart import MIMEMultipart
  5. from email.mime.text import MIMEText
  6. from threading import Thread, Lock
  7.  
  8. from selenium import webdriver
  9. from selenium.webdriver.common.keys import Keys
  10.  
  11.  
  12. def send(emailto, thr, sub):
  13. emailfrom = "sender@example.com"
  14.  
  15. username = "thorup.dk@gmail.com"
  16.  
  17. password = "iGnisteCUMbRU"
  18.  
  19. msg = MIMEMultipart('mixed')
  20.  
  21. msg["From"] = emailfrom
  22.  
  23. msg["To"] = emailto
  24.  
  25. msg["Subject"] = sub
  26.  
  27. textPart = MIMEText(thr, 'plain')
  28.  
  29. msg.attach(textPart)
  30.  
  31. server = smtplib.SMTP("smtp.gmail.com:587")
  32.  
  33. server.starttls()
  34.  
  35. server.login(username, password)
  36.  
  37. server.sendmail(emailfrom, emailto, msg.as_string())
  38.  
  39. server.quit()
  40.  
  41.  
  42. d0 = datetime.datetime.today()
  43.  
  44. d = d0 + datetime.timedelta(days=2)
  45.  
  46. day = str(d.day)
  47.  
  48. RL = ['', '', '']
  49.  
  50.  
  51. def worker(n, start):
  52. error = False
  53.  
  54. with my_lock:
  55.  
  56. driver = webdriver.Firefox()
  57.  
  58. driver.get("https://roombooking.au.dk/classes/Login.aspx?ReturnUrl=%2fclasses%2fbook.aspx")
  59.  
  60. for tries in range(50):
  61. try:
  62.  
  63. if error:
  64. driver.get("https://roombooking.au.dk/classes/Login.aspx?ReturnUrl=%2fclasses%2fbook.aspx")
  65.  
  66. driver.find_element_by_id("ctl00_Main_UsernameLbl").send_keys("20103901")
  67. driver.find_element_by_id("ctl00_Main_PasswordBox").send_keys('walboGOLDa1p', Keys.ENTER)
  68. driver.find_element_by_id('ctl00_Main_Room1_ReqSize').send_keys('5')
  69. driver.find_element_by_id('ctl00_Main_Room1_ZoneList').send_keys('f')
  70. driver.find_element_by_link_text(day).click()
  71. driver.find_element_by_id('durTemp').send_keys('4')
  72. driver.find_element_by_id('startTimeTemp').send_keys(start)
  73. driver.find_element_by_id('ctl00_Main_ShowOptionsBtn').click()
  74. driver.find_element_by_css_selector('#ctl00_Main_OptionSelector_OptionsGrid').find_elements_by_tag_name(
  75. "tr")
  76. driver.find_element_by_id('ctl00_Main_OptionSelector_OptionsGrid_ctl02_rdo').click()
  77. driver.find_element_by_id('ctl00_Main_SelectOptionButton').click()
  78.  
  79. if not error:
  80. b = datetime.datetime.now() + datetime.timedelta(days=1)
  81. sec_to_midnight = (b.replace(hour=0, minute=0, second=0, microsecond=0) - datetime.datetime.now()).total_seconds()
  82. print "wait %i seconds" % sec_to_midnight
  83. time.sleep(sec_to_midnight)
  84.  
  85.  
  86. driver.find_element_by_id('ctl00_Main_MakeBookingBtn').click()
  87. thr = driver.find_element_by_id('ctl00_Main_BookingForm1_BookingCompleted').text
  88.  
  89. RL[n] = thr
  90.  
  91. driver.close()
  92.  
  93. break
  94.  
  95.  
  96.  
  97. except:
  98.  
  99. error = True
  100.  
  101. pass
  102.  
  103. return
  104.  
  105.  
  106. my_lock = Lock()
  107.  
  108. threads = []
  109.  
  110. iterations = ['8', '12', '16']
  111.  
  112. for n, i in enumerate(iterations):
  113. t = Thread(target=worker, args=[n, i])
  114.  
  115. threads.append(t)
  116.  
  117. t.start()
  118.  
  119. t.join()
  120.  
  121. now = datetime.datetime.now()
  122.  
  123. midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
  124.  
  125. seconds = (now - midnight).seconds
  126.  
  127. send('thorup.dk@gmail.com',
  128. RL[0][30:55] + "\n \n" + RL[1][30:56] + "\n \n" + RL[2][30:56] + "\n \n in {} seconds".format(seconds),
  129. "Room bookings for {}".format(RL[0][59:70]))
  130.  
  131. send('holden750@gmail.com',
  132. RL[0][30:55] + "\n \n" + RL[1][30:56] + "\n \n" + RL[2][30:56] + "\n \n in {} seconds".format(seconds),
  133. "Room bookings for {}".format(RL[0][59:70]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement