Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to exclude by default professionnal from booking #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pip install -r requirements.txt
Run:

```
./doctoshotgun.py <city> <email> [password]
./doctoshotgun.py --pro --debug <city> <email> [password]
```

For example:
Expand All @@ -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 [email protected]
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...
[...]
```
25 changes: 15 additions & 10 deletions doctoshotgun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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

Expand Down