-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_availability.py
executable file
·52 lines (38 loc) · 1.6 KB
/
check_availability.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
#!/usr/bin/python3
import datetime
import os
import requests
from os import path
import config
current_time=str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print('--------------------------------------')
print(current_time)
def create_file(pth):
if not path.exists(pth):
with open(pth, 'w') as file:
file.write('')
print('File '+pth+' created!')
current_path = config.path+'/current.txt'
last_path = config.path+'/last.txt'
create_file(current_path)
create_file(last_path)
headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36'}
payload = {'form1': 'form1', 'form1:j_id_jsp_1457171577_15:0:j_id_jsp_1457171577_18': 'Make a Reservation', 'javax.faces.ViewState': 'j_id1:j_id2'}
with requests.session() as session:
session.get('https://secure.emybill.com/parks/reservation/base/TravisHamilton/publicSite/main.faces')
request=session.post('https://secure.emybill.com/parks/reservation/base/TravisHamilton/publicSite/main.faces', data=payload, headers=headers)
data=session.get('https://secure.emybill.com/parks/reservation/calendar?visible=true&shelter=Hamilton%20Pool%20Preserve&start=2019-08-15&end=2019-10-13')
#change start and end date if needed
#dates to check
dates = config.dates
available = ''
for entry in data.json():
if 'Available' in entry['title']:
if entry['start'][5:10] in dates:
available+=entry['start']+' '+entry['title']+'\n'
print('Availability:')
print(available)
os.remove(last_path)
os.rename(current_path, last_path)
with open(current_path, 'w') as file:
file.write(available)