forked from theriley106/Park_Notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.py
57 lines (50 loc) · 2.63 KB
/
notify.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
import time
from dateutil.parser import parse
from datetime import date as dt
import sys
import yagmail
import getpass
from selenium import webdriver
from selenium.webdriver.support.select import Select
def Email(newtext, myemail=None, password=None, sendemail=None):
if myemail == None:
myemail = str(open("email.txt", 'r').read()).partition(':')[0]
if password == None:
password = str(open("email.txt", 'r').read()).partition(':')[2]
if sendemail == None:
print("error")
yagmail.register(myemail, password)
yag = yagmail.SMTP(myemail)
yagmail.SMTP(myemail).send(sendemail, newtext, "You only have a few minutes!\n\nLink: https://www.recreation.gov/permits/233260")
print('sent email')
time_to_sleep = 60 #sleep for 60 seconds before trying again
number_of_times_checked = 0
dates_of_interest = ['Saturday, July 27, 2019', 'Saturday, August 3, 2019', 'Saturday, August 10, 2019', 'Saturday, August 17, 2019', 'Saturday, August 24, 2019', 'Saturday, August 31, 2019']
mailing_list = [line.rstrip('\n') for line in open('mailing_list.txt')]
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('log-level=3')
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://www.recreation.gov/permits/233260")
while(1):
for type in '12':
for date in dates_of_interest:
if(parse(str(dt.today())) <= parse(date)):
time.sleep(4) # Allow some time to fetch results
driver.find_element_by_xpath("//button[@id='division-selection-select']").click()
#select the item in drop-down for type of permit (day vs overnight)
time.sleep(3)
driver.find_element_by_xpath("//div[@id='division-selection']/div/div/ul/li[" + type + "]").click()
time.sleep(4) # Allow some time to fetch results
driver.find_element_by_xpath("//input[@id='number-input-']").send_keys("1") #select number of people, 1 is minimum
#fetch the availability for the specified date
availability = driver.find_element_by_xpath("//button[@aria-label='" + date + "']/div[1]/div[1]").get_attribute('aria-label')
if("Available" in availability):
output_string = "Found " + availability.split()[2] + " slots available for " + date
for email in mailing_list:
Email(output_string, sendemail=email)
else:
print("Sorry, nothing available")
driver.refresh()
time.sleep(time_to_sleep)