Skip to content

Instantly share code, notes, and snippets.

@rohith2506
Last active April 22, 2022 14:10
Show Gist options
  • Save rohith2506/c7b2d04024bc247ae936266c0d536eab to your computer and use it in GitHub Desktop.
Save rohith2506/c7b2d04024bc247ae936266c0d536eab to your computer and use it in GitHub Desktop.
import requests
from pprint import pprint
import json
import time
import argparse
current_appointment_date = '2022-02-06'
sleep_seconds = 10
class IndBioMetrics:
def __init__(self, current_appointment_date):
self.current_appointment_date = current_appointment_date
self.availability_url = "https://oap.ind.nl/oap/api/desks/AM/slots/?productKey=BIO&persons=1"
self.book_url = "https://oap.ind.nl/oap/api/desks/AM/appointments"
self.book_payload = {"bookableSlot":{"key":"13edb76c989563403c534ce563b3caeb","date":"2022-03-30","startTime":"09:10","endTime":"09:20","parts":1,"booked":"false"},"appointment":{"productKey":"BIO","date":"2022-03-30","startTime":"09:10","endTime":"09:20","email":"<your_email_address>","phone":"<your_phone_number>","language":"en","customers":[{"firstName":"<your_first_name>","lastName":"<your_last_name>","vNumber":"<your_vnr_number>"}]}}
self.headers = {'content-type': 'application/json'}
def get_available_slots(self):
try:
resp = requests.get(self.availability_url)
raw_data = resp.text.strip().split("\n")[1]
timings = json.loads(raw_data)
result = timings.get('data', [])[:5]
for res in result:
available_date = res.get('date')
if available_date < self.current_appointment_date:
return res
else:
print("Available date {} is far from current date {}".format(available_date, self.current_appointment_date))
return None
except Exception as err:
print("Error running the available slots. Error: {}".format(str(err)))
def book_appointment_slot(self, result):
self.book_payload['bookableSlot']['key'] = result['key']
self.book_payload['bookableSlot']['startTime'] = result['startTime']
self.book_payload['bookableSlot']['endTime'] = result['endTime']
self.book_payload['bookableSlot']['date'] = result['date']
self.book_payload['appointment']['date'] = result['date']
self.book_payload['appointment']['startTime'] = result['startTime']
self.book_payload['appointment']['endTime'] = result['endTime']
response = requests.post(self.book_url, data=json.dumps(self.book_payload), headers=self.headers)
if response.status_code == 200:
return True
else:
print("Appointment creation failed. Error: {}".format(response.text))
return False
if __name__ == "__main__":
ind_bio_metris_obj = IndBioMetrics("2022-04-06")
sleep_seconds = 10
while True:
output = ind_bio_metris_obj.get_available_slots()
if output:
print("Availability found. Here's the output: {}".format(str(output)))
if ind_bio_metris_obj.book_appointment_slot(output):
print("Appointment booked")
break
print("Sleeping for {} seconds.".format(sleep_seconds))
time.sleep(sleep_seconds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment