-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathncdmv.py
70 lines (50 loc) · 2.09 KB
/
ncdmv.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
#!/usr/bin/python3
import requests
import datetime
import time
startdaysout = 7
checkdays = 14
locations = {"Carrboro": "140",
"Cary": "66",
"Durham South": "80",
"Hillsborough": "52",
"Siler City": "109",
"Sanford": "54"
}
headers = {
'Connection': 'close',
'Cache-Control': 'max-age=0',
'DNT': '1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.40 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Accept-Language': 'en-US,en;q=0.9,es;q=0.8,la;q=0.7',
}
s = requests.Session()
s.keep_alive = False
# Load the main page incase we need to to trigger any application logic
s.get("https://skiptheline.ncdot.gov/Webapp/_/_/_/en/WizardAppt/AppointmentTypes", headers=headers)
# Set your appointment type
s.post("https://skiptheline.ncdot.gov/Webapp/_/_/_/en/WizardAppt/SelectAppointmentType", headers=headers, data={"apptType": "Teen Driver Level 1"})
for location in locations:
# Set the location via a post
print("Setting location to %s" %location)
s.post('https://skiptheline.ncdot.gov/Webapp/_/_/_/en/WizardAppt/SelectedUnit', headers=headers, data={'unitId': locations[location]})
# Iterate through days to check for appointments
for day in range(checkdays):
date = datetime.date.today()+datetime.timedelta(days=startdaysout) + datetime.timedelta(days=day)
#Skip weekends
if date.weekday() in (5,6):
continue
# Don't flood them
time.sleep(1)
url = "%s?date=%s&_=%s" %("https://skiptheline.ncdot.gov/Webapp/_/_/_/en/WizardAppt/SlotsTime", date.strftime("%m/%d/%Y"), int(time.time()))
print("Fetching", url)
# dont bother retrying just fail and continue
try:
r = s.get(url, headers=headers).json()
if "Result" in r and r["Result"]:
print("DMV APPOINTMENT FOUND: %s @ %s https://skiptheline.ncdot.gov/Webapp/_/_/_/en/WizardAppt/Units?input=Appointment" %(date,location), r)
except:
print("Error, skipping")
continue