-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
85 lines (66 loc) · 3.2 KB
/
app.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
import logging
from datetime import datetime
from exceptions import SmoobuAPIError
from interfaces.formatter import Formatter
from services.smoobu_service import SmoobuService
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
class SmoobuApp:
"""
🏨 Main Application for Smoobu API Interactions
This class orchestrates the interactions with the Smoobu API, formatting the results,
and presenting the information.
🔑 Features:
- Retrieves user information, reservations, and bookings
- Uses various formatters to present the data in a readable format
- Handles errors and provides logging
🔗 Dependencies:
- SmoobuService for API interactions
- Various Formatter implementations for data presentation
"""
def __init__(self, service: SmoobuService, reservations_formatter: Formatter,
user_formatter: Formatter, booking_list_formatter: Formatter,
unoccupied_days_formatter: Formatter):
"""
Initialize the SmoobuApp with necessary services and formatters.
Args:
service (SmoobuService): Service for Smoobu API interactions.
reservations_formatter (Formatter): Formatter for reservations data.
user_formatter (Formatter): Formatter for user information.
booking_list_formatter (Formatter): Formatter for booking lists.
unoccupied_days_formatter (Formatter): Formatter for unoccupied days.
"""
self.service = service
self.reservations_formatter = reservations_formatter
self.user_formatter = user_formatter
self.booking_list_formatter = booking_list_formatter
self.unoccupied_days_formatter = unoccupied_days_formatter
def run(self):
"""
📊 Execute the main application logic.
This method:
1. Retrieves and displays user information
2. Fetches and displays reservations
3. Organizes and displays bookings by apartment
4. Analyzes and displays unoccupied days
🚫 Error Handling:
Catches and logs any SmoobuAPIError that occurs during execution.
"""
logger.info("Starting Smoobu API Request Script")
print("Smoobu API Request Script")
print("=" * 30)
print(f"Current Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print("-" * 30)
try:
user_info = self.service.get_user_info()
# print(self.user_formatter.format(user_info))
reservations = self.service.get_reservations()
# print(self.reservations_formatter.format(reservations))
bookings_by_apartment = self.service.get_bookings_by_apartment()
# print(self.booking_list_formatter.format(bookings_by_apartment))
unoccupied_days_analysis = self.unoccupied_days_formatter.format(bookings_by_apartment)
print(unoccupied_days_analysis)
logger.info("Analysis complete. Messages sent to hosts for relevant bookings.")
except SmoobuAPIError as e:
logger.error(f"An error occurred: {e}")
logger.info("Smoobu API Request Script completed")