forked from m-grzesiak/yalma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yalma.py
91 lines (71 loc) · 4.3 KB
/
yalma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from datetime import date
import click
from tabulate import tabulate
import booking_service
import config_loader
import report_service
from luxmed_api import Language
@click.group()
def main():
config_loader.initialize_app_configuration()
@main.command(help="get a list of available cities")
def cities():
retrieved_cities = booking_service.get_cities()
__display_results(retrieved_cities, ["city ID", "city name"])
@main.command(help="get a list of available clinics")
@click.option("-c", "--city-id", type=int, required=True, help="return a list of clinics for the given city ID")
@click.option("-s", "--service-id", type=int, required=True, help="a service that doctors should be specialized in")
def clinics(city_id, service_id):
retrieved_clinics = booking_service.get_clinics(city_id, service_id)
__display_results(retrieved_clinics, ["clinic ID", "clinic name"])
@main.command(help="get a list of available doctors")
@click.option("-c", "--city-id", type=int, required=True, help="a city where doctors should be located")
@click.option("-s", "--service-id", type=int, required=True, help="a service that doctors should be specialized in")
@click.option("-cl", "--clinic-id", type=int, help="a clinic where you are looking for doctors")
def doctors(city_id, service_id, clinic_id):
retrieved_doctors = booking_service.get_doctors(city_id, service_id, clinic_id)
__display_results(retrieved_doctors, ["doctor ID", "doctor name"])
@main.command(help="get a list of available services")
def services():
retrieved_services = booking_service.get_services()
__display_results(retrieved_services, ["service ID", "service name"])
@main.command(help="monitor the availability of visits for the given criteria")
@click.option("-e", "--email", type=str, required=True, help="send monitoring report to the given email address")
@click.option("-c", "--city-id", type=int, required=True, help="monitor visits in the given city")
@click.option("-s", "--service-id", type=int, required=True, help="monitor visits for the given service")
@click.option("-f", "--from-date", type=click.DateTime(formats=["%Y-%m-%d"]), default=str(date.today()),
show_default=True,
help="start from the given date. The date should be in a year-month-day format. Example: 2020-11-30. "
"If the user does not specify the date, today's date will be chosen")
@click.option("-t", "--to-date", type=click.DateTime(formats=["%Y-%m-%d"]), required=True,
help="finish on the given date. The date should be in a year-month-day format. "
"Example: 2020-11-30")
@click.option("-td", "--time-of-day", type=click.IntRange(0, 3),
default=0, show_default=True,
help="time of day. If not provided, all day will be considered. Possible values: "
"0 - all day, "
"1 - until 12:00, "
"2 - from 12:00 to 17:00, "
"3 - after 17:00")
@click.option("-l", "--language", type=click.Choice(["pl", "eng"], case_sensitive=False), default="pl",
show_default=True, help="the language in which the doctor communicates with a patient")
@click.option("-d", "--doctor-id", type=int, help="monitor visits for the given doctor")
@click.option("-cl", "--clinic-id", type=int, help="monitor visits in the given clinic")
def monitor(email, city_id, service_id, from_date, to_date, time_of_day, language, clinic_id=None, doctor_id=None):
parsed_from_date = from_date.date()
parsed_to_date = to_date.date()
parsed_language = __resolve_language(language)
available_terms = booking_service.get_available_terms(city_id, service_id, parsed_from_date, parsed_to_date,
time_of_day, parsed_language, clinic_id, doctor_id)
report_service.make_report(available_terms, email)
def __display_results(results: {}, headers: [str]):
if results:
parsed_results = [(item["id"], item["name"]) for item in results]
table_view = tabulate(parsed_results, headers=headers, tablefmt="psql")
print(table_view)
else:
print("No results have found for given criteria")
def __resolve_language(language: str) -> Language:
return Language.POLISH if language == "pl" else Language.ENGLISH
if __name__ == "__main__":
main()