Skip to content

Instantly share code, notes, and snippets.

@apsun
Created February 27, 2019 18:23
Show Gist options
  • Save apsun/7ad329ea18af624b438429c51006e663 to your computer and use it in GitHub Desktop.
Save apsun/7ad329ea18af624b438429c51006e663 to your computer and use it in GitHub Desktop.
import datetime
import random
import time
import requests
import bs4
DATE = "Wed, 3 Apr 2019"
TIME = "0900"
COOKIE = """
<your cookie here>
"""
def randsleep():
while True:
wait = random.gauss(300, 120)
if 60 < wait < 600:
break
time.sleep(wait)
def firstappt():
resp = requests.post(
url="https://www.dmv.ca.gov/wasapp/foa/findDriveTest.do",
headers={
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Referer": "https://www.dmv.ca.gov/wasapp/foa/findDriveTest.do",
"Cookie": COOKIE.strip(),
},
data={
"formattedRequestedDate": DATE,
"requestedTime": TIME,
"checkAvail": "Check+for+Availability",
},
)
bs = bs4.BeautifulSoup(resp.text, "lxml")
form = bs.find(id="ApptForm")
appt = form.find(attrs={"data-title": "Appointment"})
lines = list(filter(None, map(str.strip, appt.text.splitlines())))
if len(lines) == 2:
return datetime.datetime.strptime(lines[1], "%A, %B %d, %Y at %I:%M %p")
else:
return None
while True:
appt = firstappt()
print(appt)
randsleep()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment