-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
45 lines (36 loc) · 1.67 KB
/
utils.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
import logging
import sys
from datetime import datetime, timedelta
from typing import Dict, List
import constants
def get_logger(name: str):
root = logging.getLogger(name=name)
root.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
root.addHandler(handler)
return root
def extract_time_from_token(token: str):
"""extract time from token that looks like:
rgs://resy/2/1843946/2/2022-12-18/2022-12-18/20:15:00/2/Indoor Dining"""
split_token = token.split('/')
return split_token[-3]
def is_outdoor_slot(token: str):
"""Determine whether or not reservation is outdoors. Token input looks like:
rgs://resy/2/1843946/2/2022-12-18/2022-12-18/20:15:00/2/Indoor Dining"""
slot_loc = token.split('/')[-1].lower()
return any(kw in slot_loc for kw in constants.OUTDOOR_SLOT_KEYWORDS)
def get_times_to_tokens(config_ids: List[str], indoor_only: bool) -> Dict[str, str]:
if indoor_only:
return {extract_time_from_token(config_id): config_id for config_id in config_ids if not is_outdoor_slot(config_id)}
else:
return {extract_time_from_token(config_id): config_id for config_id in config_ids}
def get_next_booking_time(time_to_book: str) -> datetime:
hour, minute = time_to_book.split(":")
now = datetime.now()
next_time_to_book = datetime(now.year, now.month, now.day, hour=int(hour), minute=int(minute), second=0, microsecond=0)
if now > next_time_to_book:
next_time_to_book += timedelta(days=1)
return next_time_to_book