diff --git a/README.md b/README.md index 8b8b09f..86ac974 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ pip install -r requirements.txt Run: ``` -./doctoshotgun.py [password] +./doctoshotgun.py --pro --debug [password] ``` For example: @@ -37,3 +37,16 @@ Password: ::: Booking status: True ::: Booked! ``` + +If you don't set --pro it will avoid vaccination center within 'professionnel' in the place name + +``` +$ ./doctoshotgun.py --pro paris roger.philibert@gmail.com +Password: +[...] +::: Looking for slots in place Institut Cœur Poumon +::: First slot not found :( +::: Not looking for slots in place Centre de vaccination - Professionnels de santé et assimilés, as it's reserved for 'professionnel' +::: Fail, try next center... +[...] +``` diff --git a/doctoshotgun.py b/doctoshotgun.py index 2047939..443040a 100755 --- a/doctoshotgun.py +++ b/doctoshotgun.py @@ -198,7 +198,7 @@ def get_patients(self): return self.page.get_patients() - def try_to_book(self, center): + def try_to_book(self, center, pro): self.open(center['url']) p = urlparse(center['url']) center_id = p.path.split('/')[-1] @@ -213,15 +213,19 @@ def try_to_book(self, center): return False for place in self.page.get_places(): - log('Looking for slots in place %s', place['name']) - practice_id = place['practice_ids'][0] - agenda_ids = center_page.get_agenda_ids(motive_id, practice_id) - if len(agenda_ids) == 0: - # do not filter to give a chance - agenda_ids = center_page.get_agenda_ids(motive_id) + # Add regexp search for "professionnel" in the place['name'] + if not pro and re.search("professionnel", place['name'], re.IGNORECASE): + log('Not looking for slots in place %s, as it\'s reserved for \'professionnel\'', place['name']) + else: + log('Looking for slots in place %s', place['name']) + practice_id = place['practice_ids'][0] + agenda_ids = center_page.get_agenda_ids(motive_id, practice_id) + if len(agenda_ids) == 0: + # do not filter to give a chance + agenda_ids = center_page.get_agenda_ids(motive_id) - if self.try_to_book_place(profile_id, motive_id, practice_id, agenda_ids): - return True + if self.try_to_book_place(profile_id, motive_id, practice_id, agenda_ids): + return True return False @@ -340,6 +344,7 @@ class Application: def main(self): parser = argparse.ArgumentParser(description="Book a vaccine slot on Doctolib") parser.add_argument('--debug', '-d', action='store_true', help='show debug information') + parser.add_argument('--pro', '-p', action='store_true', help='search on place with \'professionnel\'') parser.add_argument('city', help='city where to book') parser.add_argument('username', help='Doctolib username') parser.add_argument('password', nargs='?', help='Doctolib password') @@ -382,7 +387,7 @@ def main(self): log('Trying to find a slot in %s', center['name_with_title']) - if docto.try_to_book(center): + if docto.try_to_book(center, args.pro): log('Booked!') return 0