Last active
September 22, 2021 11:14
-
-
Save JeckLabs/e0552610fa0355b45a2a3f4c6f7f9d3b to your computer and use it in GitHub Desktop.
Bot for checking earliest available slots at met.overseasregistrations.uk
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
# pip3 install requests | |
import requests | |
from datetime import datetime, timedelta | |
import re | |
import sys | |
import webbrowser | |
import time | |
import urllib3.exceptions | |
import requests.exceptions | |
# Get one from @botfather | |
TELEGRAM_BOT_TOKEN = '' | |
# You could get your chat id from @userinfobot | |
TELEGRAM_CHAT_ID = 0 | |
# Browser cookies after authorization at met.overseasregistrations.uk | |
cookies = { | |
'cookieAccepted': 'true', | |
'__RequestVerificationToken': '', | |
'ASP.NET_SessionId': '', | |
'FNFEAuth': '', | |
} | |
default_headers = { | |
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/537.36', | |
} | |
def exit(e): | |
requests.post( | |
f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage", | |
json={"chat_id": TELEGRAM_CHAT_ID, "text": "OVRO bot failed, sorry..."} | |
) | |
raise e | |
s = requests.Session() | |
min_dt = None | |
today = datetime.now().replace(microsecond=0, second=0, minute=0) | |
selected_date = today.strftime("%Y-%m-%dT%H:%M:%S.000Z") | |
while True: | |
print("Start cycle...") | |
try: | |
r = s.get( | |
"https://met.overseasregistrations.uk/Appointment/Book", | |
cookies=cookies, headers=default_headers, | |
timeout=10 | |
) | |
venues = re.findall(r'option value="(.*?)" data-location="(.*?)"', r.text) | |
for venue in venues: | |
venue_id = venue[0] | |
venue_name = venue[1] | |
r = s.post( | |
'https://met.overseasregistrations.uk/Appointment/GetNextAppointments', | |
cookies=cookies, headers=default_headers, | |
timeout=10, | |
json={'schedulerView': 'Week', 'selectedDate': selected_date, 'venueId': venue_id} | |
) | |
data = r.json() | |
appointments = data['sData']['SchedulerItems'] | |
for appointment in appointments: | |
ts = int(re.sub(r'\D', '', appointment['Start'])) // 1000 | |
dt = datetime.utcfromtimestamp(ts) | |
if min_dt is None or dt < min_dt: | |
notification_text = f"Found earlier OVRO appointment: {dt:%Y-%m-%d}, venue: {venue_name}\n" | |
requests.post( | |
f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage", | |
json={"chat_id": TELEGRAM_CHAT_ID, "text": notification_text} | |
) | |
print(notification_text) | |
min_dt = dt | |
except (urllib3.exceptions.TimeoutError, requests.exceptions.Timeout): | |
print("Timeout...") | |
time.sleep(60) | |
except Exception as e: | |
exit(e) | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment