Created
November 26, 2020 22:12
-
-
Save joshma/f4c6bb954596d7d339d23d2ee81053b4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
from sendgrid import SendGridAPIClient | |
from sendgrid.helpers.mail import Mail | |
import requests | |
import time | |
url = "https://home.color.com/api/v1/sample_collection_appointments/availability?claim_token=7a4da7f7181ef9d06ef87df9872731e67c39&collection_site=Embarcadero" | |
# Go to https://home.color.com/covid/sign-up/start?partner=sfdph | |
# Complete it once, and then look at the XHR sent to the URL above | |
# Copy out the CSRF token and the cookie below | |
csrf_token = "FILL_ME_IN" | |
cookie = "FILL_ME_IN" | |
def date_works(start_date): | |
for pos in ["2020-11-24", "2020-11-25", "2020-11-26"]: | |
if start_date.startswith(pos): | |
return True | |
return False | |
def send_notice(appts): | |
print("FOUND {} APPOINTMENTS".format(len(appts))) | |
message = Mail( | |
from_email="me@joshma.com", | |
to_emails="me@joshma.com", | |
subject="COVID APPOINTMENTS FOUND", | |
html_content="<strong>Appointments:</strong><br><pre>{}</pre>".format( | |
json.dumps(appts, indent=2) | |
), | |
) | |
try: | |
sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY")) | |
response = sg.send(message) | |
except Exception as e: | |
print(e) | |
while True: | |
rv = requests.get( | |
url, | |
headers={ | |
"X-CSRFToken": csrf_token, | |
"Cookie": cookie, | |
}, | |
) | |
d = rv.json() | |
appts = [a for a in d if date_works(a["start"])] | |
if len(appts) > 0: | |
send_notice(appts) | |
print("Waiting 10min before continuing") | |
time.sleep(60 * 10) | |
else: | |
print("No appointments, waiting 30sec") | |
time.sleep(30) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment