From ab18c04d92bcacac506eb7dd871a04611b32f740 Mon Sep 17 00:00:00 2001 From: Lea Date: Sun, 1 Sep 2024 18:22:01 +0200 Subject: [PATCH] add empty results and remove therapists without phone numbers --- app.py | 11 +++++++---- arztapi/APIHandler.py | 8 +++++--- templates/no_result.html | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 templates/no_result.html diff --git a/app.py b/app.py index 89a42f5..d424ed4 100644 --- a/app.py +++ b/app.py @@ -39,10 +39,13 @@ def search_for_doctors_with_params(): return redirect("/") api_handler = APIHandler() - locations = api_handler.get_lat_lon_location_list(location)[0] - base64_value = api_handler.calculate_req_value_base64(float(locations["lat"]), float(locations["lon"])) - api_handler.get_list_of_doctors(float(locations['lat']), float(locations['lon']), base64_value, therapy_types, - therapy_age_range, therapy_setting) + locations = api_handler.get_lat_lon_location_list(location) + if not locations: + return render_template("no_result.html") + location_match = locations[0] + base64_value = api_handler.calculate_req_value_base64(float(location_match["lat"]), float(location_match["lon"])) + api_handler.get_list_of_doctors(float(location_match['lat']), float(location_match['lon']), base64_value, + therapy_types, therapy_age_range, therapy_setting) api_handler.get_general_doctor_information() api_handler.filter_doctor_information_for_distance(distance*1000) sorted_doctor_phone_times = api_handler.get_doctor_phone_times_sorted(amount_of_weeks) diff --git a/arztapi/APIHandler.py b/arztapi/APIHandler.py index d7db73d..8220caf 100644 --- a/arztapi/APIHandler.py +++ b/arztapi/APIHandler.py @@ -35,7 +35,6 @@ class APIHandler: return response.json() except JSONDecodeError: - print("foo") print(response.text) def get_list_of_doctors(self, lat, lon, req_val_base64, therapy_types, therapy_age, @@ -95,6 +94,9 @@ class APIHandler: def get_general_doctor_information(self) -> List[DoctorInformation]: general_doctor_information = [] for data in self.phone_times.arztPraxisDatas: + # Remove empty phone number fields + if data.tel == "": + continue doctor_day_times = data.tsz phone_times = [] for day in doctor_day_times: @@ -238,8 +240,8 @@ class APIHandler: try: if "24:00" in date_string: # Sometimes the API returns 24:00 as time, so filtering for those cases and replacing it with a minute - # less to work with propery input - date_string =date_string.replace("24:00", "23:59") + # less to work with proper input + date_string = date_string.replace("24:00", "23:59") # Add the current year since it is not part of the original date sent by the API parsed_date = datetime.strptime(date_string, format_string).replace(year=datetime.now().year) diff --git a/templates/no_result.html b/templates/no_result.html new file mode 100644 index 0000000..1b8639c --- /dev/null +++ b/templates/no_result.html @@ -0,0 +1,16 @@ +{% extends "base.html" %} + +{% block content %} +
+
+
+

Keine Ergebnisse

+
+ Keine Telefonzeiten mit gegebenem Standort und Distanz gefunden + Zurück zur Suche, um es erneut zu versuchen +
+
+
+
+ +{% endblock %} \ No newline at end of file