theraPy/app.py
2024-08-27 23:09:19 +02:00

52 lines
1.7 KiB
Python

import locale
from flask import Flask, render_template, request
from forms.SearchForm import SearchForm
from arztapi.APIHandler import APIHandler
app = Flask(__name__)
app.secret_key = "nosecretkey"
locale.setlocale(locale.LC_ALL, 'de_DE.UTF-8')
@app.route('/')
def main_page():
search_form = SearchForm()
return render_template("index.html", form=search_form)
@app.route("/search", methods=["POST"])
def search_for_doctors_with_params():
search_form = SearchForm(request.form)
if search_form.validate():
location = search_form.location.data
distance = search_form.therapy_distance.data
therapy_types = search_form.therapy_type.data
therapy_age_range = search_form.therapy_age_range.data
therapy_setting = search_form.therapy_setting.data
print(f"Location: {location}")
print(f"Distance: {distance}")
print(f"Therapy Types: {therapy_types}")
print(f"Age Range: {therapy_age_range}")
print(f"Therapy Setting: {therapy_setting}")
else:
print(search_form.errors)
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)
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()
return render_template("result.html", doctors=sorted_doctor_phone_times)
if __name__ == '__main__':
app.run()