Skip to content

Commit

Permalink
fixes: 1. removed captcha prompt while scheduling appointment (no lon…
Browse files Browse the repository at this point in the history
…ger required)

2. updated README.md and requirements.txt
3. minor bug fixes and improvements
  • Loading branch information
divagicha committed Jun 8, 2021
1 parent b0b20cc commit e6c4a1b
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 223 deletions.
58 changes: 29 additions & 29 deletions CovidVaccineChecker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import re
# import sys
from sys import exit
import json
import time
import random
Expand All @@ -10,7 +10,7 @@
from inspect import stack
from hashlib import sha256
import PySimpleGUI as simpleGUI
from CovidVaccineChecker.captcha import captcha_builder
# from CovidVaccineChecker.captcha import captcha_builder


def getCallingScriptFilename():
Expand Down Expand Up @@ -285,7 +285,7 @@ def create_new_user_config(self, user_config_file):
f"at that centre only. You can still enter a centre's name below as your preference as there might be other sessions as well in "
f"the same centre with different 'Min Age, Available Capacity and Slots' value.{TextColors.ENDC}")
centre_preferences = input(f"\n-->\tEnter short/full centre name for centre preference "
f"{TextColors.WARNING}(comma-separated in case of multiple){TextColors.ENDC}: ")
f"{TextColors.WARNING}(comma-separated in case of multiple), CAN BE BLANK AS WELL{TextColors.ENDC}: ")

if centre_preferences is not None and centre_preferences.strip() != "":
self.centre_preferences = centre_preferences.strip().replace(', ', ',').replace(' ,', ',').lower().split(",")
Expand Down Expand Up @@ -678,25 +678,25 @@ def get_appointment_details(appointment_dict):
return appointment_details


def generate_captcha(self, user_config_file, is_app_gui):
print(f"\n{TextColors.HEADER}============================= GENERATING CAPTCHA ============================={TextColors.ENDC}")

while True:
response = requests.request("POST", self.captcha_url, headers=self.auth_headers)

if response.status_code == 200:
print(f"\nCAPTCHA GENERATED!!!")
# with open("response_captcha.json", "w") as captcha_json_file:
# captcha_json_file.write(json.dumps(response.json(), indent=4))
return captcha_builder(response.json())
else:
if "unauthenticated access" in response.text.lower():
if is_app_gui:
return '<REFRESH_TOKEN>'
self.generateUserToken(user_config_file, refresh_token=True)
else:
print(f"\n{TextColors.FAIL}FAILED ATTEMPT (message: could not generate captcha){TextColors.ENDC} (response: {response.text})... trying again in 1 sec.")
time.sleep(1)
# def generate_captcha(self, user_config_file, is_app_gui):
# print(f"\n{TextColors.HEADER}============================= GENERATING CAPTCHA ============================={TextColors.ENDC}")
#
# while True:
# response = requests.request("POST", self.captcha_url, headers=self.auth_headers)
#
# if response.status_code == 200:
# print(f"\nCAPTCHA GENERATED!!!")
# # with open("response_captcha.json", "w") as captcha_json_file:
# # captcha_json_file.write(json.dumps(response.json(), indent=4))
# return captcha_builder(response.json())
# else:
# if "unauthenticated access" in response.text.lower():
# if is_app_gui:
# return '<REFRESH_TOKEN>'
# self.generateUserToken(user_config_file, refresh_token=True)
# else:
# print(f"\n{TextColors.FAIL}FAILED ATTEMPT (message: could not generate captcha){TextColors.ENDC} (response: {response.text})... trying again in 1 sec.")
# time.sleep(1)


def isValidCentre(self, centre, min_age_limit):
Expand Down Expand Up @@ -741,12 +741,12 @@ def schedule_appointment(self, all_centres, ref_ids, dose_number, min_age_limit,
if self.isValidCentre(centre, min_age_limit) or dummy_centre_check:
print(f"{TextColors.BOLD}{TextColors.WARNING}(VALID CENTRE FOUND - Booking Appointment...){TextColors.ENDC}")
if centre['available_capacity_dose'+str(dose_number)] >= len(ref_ids):
captcha = self.generate_captcha(user_config_file, is_app_gui)

if captcha == '<REFRESH_TOKEN>' and is_app_gui:
return False, '<REFRESH_TOKEN>'

print(f"\n{TextColors.BLACKONGREY}Entered Captcha Value: {captcha}{TextColors.ENDC}")
# captcha = self.generate_captcha(user_config_file, is_app_gui)
#
# if captcha == '<REFRESH_TOKEN>' and is_app_gui:
# return False, '<REFRESH_TOKEN>'
#
# print(f"\n{TextColors.BLACKONGREY}Entered Captcha Value: {captcha}{TextColors.ENDC}")

payload = json.dumps({
"dose": dose_number,
Expand All @@ -755,7 +755,7 @@ def schedule_appointment(self, all_centres, ref_ids, dose_number, min_age_limit,
# "slot": self.slot_preference,
"slot": self.getUserSlotPreference(centre) if not is_app_gui else self.getUserSlotPreferencePopup(centre),
"beneficiaries": ref_ids,
"captcha": captcha
# "captcha": captcha
})

response = requests.request("POST", self.schedule_url, headers=self.auth_headers, data=payload)
Expand Down
68 changes: 0 additions & 68 deletions CovidVaccineChecker/captcha.py

This file was deleted.

8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,22 @@ As it's a difficult task to schedule an appointment for CoVid-Vaccine with only
```sh
pip install -r requirements.txt
```
6. Run the script to enter your details and book a vaccination slot
6. Run the script **(Console App)** to enter your details and book a vaccination slot
```sh
python schedule_vaccination_appointment.py
```
7. Run the following command for **GUI version of the App**
```sh
python scheduler_form.py
```



<!-- INSTALLATION -->
<a name="installation-via-exe-file"></a>
### Installation (via EXE file)

1. Navigate to the **'dist'** directory for the setup file or click [here](https://github.com/DivAgicha/CoWIN-Vaccine-Appointment-Booking/raw/master/dist/CovidVaccinationAppointmentScheduler-Setup-v2.0.exe) to download the same for Windows.
1. Navigate to the **'dist'** directory for the setup file or click [here](https://github.com/DivAgicha/CoWIN-Vaccine-Appointment-Booking/raw/master/dist/CovidVaccinationAppointmentScheduler-Setup-v2.1.exe) to download the same for Windows.
2. Double-click the installer file and follow the instructions to install the program.
3. Upon successful installation you will find `Covid Vaccination Appointment Scheduler` folder in your `C:\Program Files (x86)\` directory.
4. Open the folder and run `schedule_vaccination_appointment.exe` (Console App) or `scheduler_form.exe` (GUI App) file.
Expand Down
Binary file not shown.
13 changes: 2 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
cairocffi==1.2.0
CairoSVG==2.5.2
certifi==2020.12.5
cffi==1.14.5
certifi==2021.5.30
chardet==4.0.0
cssselect2==0.4.1
defusedxml==0.7.1
idna==2.10
Pillow==8.2.0
pycparser==2.20
PySimpleGUI==4.43.0
requests==2.25.1
tabulate==0.8.9
tinycss2==1.1.0
urllib3==1.26.4
webencodings==0.5.1
urllib3==1.26.5
13 changes: 8 additions & 5 deletions schedule_vaccination_appointment.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
if not os.path.exists(os.path.join(cowinAPI.BASE_PROJECT_DIR, "user_data/")):
os.makedirs(os.path.join(cowinAPI.BASE_PROJECT_DIR, "user_data/"))

if not os.path.exists(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/")):
os.makedirs(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/"))
# if not os.path.exists(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/")):
# os.makedirs(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/"))

user_config_file = os.path.join(cowinAPI.BASE_PROJECT_DIR, "user_data/user_config_" + mobile + ".json")

Expand Down Expand Up @@ -166,10 +166,13 @@
print(f"\n-->\tAttempting to book appointment {TextColors.WARNING}(every 3 seconds for next 4 minutes, i.e., total 80 attempts)"
f"{TextColors.ENDC}")

# input(f"\n{TextColors.BOLD}Note: keep an eye on the screen when the process starts, as when a valid centre "
# f"gets available you will be asked to enter {TextColors.WARNING}captcha{TextColors.ENDC} {TextColors.BOLD}and select "
# f"{TextColors.WARNING}time slot{TextColors.ENDC} {TextColors.BOLD}to book and confirm the appointment{TextColors.ENDC}"
# f"\n\nPress 'Enter' to continue...")
input(f"\n{TextColors.BOLD}Note: keep an eye on the screen when the process starts, as when a valid centre "
f"gets available you will be asked to enter {TextColors.WARNING}captcha{TextColors.ENDC} {TextColors.BOLD}and select "
f"{TextColors.WARNING}time slot{TextColors.ENDC} {TextColors.BOLD}to book and confirm the appointment{TextColors.ENDC}"
f"\n\nPress 'Enter' to continue...")
f"gets available you will be asked to select a {TextColors.WARNING}time slot{TextColors.ENDC} "
f"{TextColors.BOLD}to book and confirm the appointment{TextColors.ENDC}\n\nPress 'Enter' to continue...")

all_centres = cowinAPI.findCentresBySearchCriteria()

Expand Down
15 changes: 9 additions & 6 deletions scheduler_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def create_window(finalize=False):
simpleGUI.Button('Next', key='next_min_age_limit')]
])],

[simpleGUI.Text('Made with (https://github.com/divagicha/\nCoWIN-Vaccine-Appointment-Booking)', auto_size_text=True, font='Courier 8'),
[simpleGUI.Text('Made with ' + u'\u2665' + ' (https://github.com/divagicha/\nCoWIN-Vaccine-Appointment-Booking)', auto_size_text=True, font='Courier 8'),
simpleGUI.Button('Reset Form', key='clear_values', tooltip="This will clear all the above values", size=(11, 1), button_color='Yellow'),
simpleGUI.Exit('Exit', size=(11, 1), button_color='Yellow')]]
simpleGUI.Exit('Exit', size=(11, 1), button_color='Yellow', pad=(10,0))]]

colR1C2 = [[simpleGUI.Frame('Output', font='Any 8', layout=[
[simpleGUI.Output(size=(80, 35), key='console_output', font='Courier 10', echo_stdout_stderr=True)]
Expand Down Expand Up @@ -198,9 +198,12 @@ def isInputFieldActive(key):

def attempt_to_schedule_appointment():
global next_operation, attempts, all_centres
# simpleGUI.popup("Attempting to schedule appointment (every 3 seconds for next 4 minutes, i.e., total 80 attempts)\n\nNote: keep an "
# "eye on the screen when the process starts, as when a valid centre gets available you will be asked to enter CAPTCHA "
# "and select TIME SLOT to book and confirm your appointment", title="Scheduling Your Appointment")
simpleGUI.popup("Attempting to schedule appointment (every 3 seconds for next 4 minutes, i.e., total 80 attempts)\n\nNote: keep an "
"eye on the screen when the process starts, as when a valid centre gets available you will be asked to enter CAPTCHA "
"and select TIME SLOT to book and confirm your appointment", title="Scheduling Your Appointment")
"eye on the screen when the process starts, as when a valid centre gets available you will be asked to select a "
"TIME SLOT to book and confirm your appointment", title="Scheduling Your Appointment")

all_centres = cowinAPI.findCentresBySearchCriteria()

Expand Down Expand Up @@ -323,8 +326,8 @@ def call_schedule_appointment():
if not os.path.exists(os.path.join(cowinAPI.BASE_PROJECT_DIR, "user_data/")):
os.makedirs(os.path.join(cowinAPI.BASE_PROJECT_DIR, "user_data/"))

if not os.path.exists(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/")):
os.makedirs(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/"))
# if not os.path.exists(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/")):
# os.makedirs(os.path.join(cowinAPI.BASE_PROJECT_DIR, "captcha/"))

key_list = list(window.key_dict.keys())
keys_to_remove = ['col1', 'col2', 'console_output', 'clear_values', 'Exit']
Expand Down
Binary file removed utilities/convert.exe
Binary file not shown.
Loading

0 comments on commit e6c4a1b

Please sign in to comment.