Skip to content
Snippets Groups Projects
Commit 0504e191 authored by fmk17's avatar fmk17
Browse files

Fix two digit year and timezone issues

parent 56523ccc
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ LocationDays = namedtuple("LocationDays", "days, location, update_datetime")
cached_update_times: Dict[Location, datetime] = dict()
cached_responses: Dict[Location, LocationDays] = dict()
DATE_REGEX = r": (\d{1,2})\/(\d{1,2})\/(\d{4})"
DATE_REGEX = r": (\d{1,2})\/(\d{1,2})\/(\d{2,4})"
logger = logging.getLogger("crawler")
......@@ -52,6 +52,8 @@ def get_location_days(
if date_re is None:
break
d, m, y = map(int, date_re.groups())
if y < 100:
y += 2000
table_children = iter(table_node.select("td"))
menus = []
for title_node, item_nodes in zip(table_children, table_children):
......@@ -90,7 +92,9 @@ def get_location_days(
name=item_name, indicators=frozenset(item_indicators)
)
)
menus.append(Menu(meal_name=title_node.text, items=tuple(items)))
menus.append(
Menu(meal_name=title_node.text.strip(), items=tuple(items))
)
days.append(Day(date=date(y, m, d), date_raw=date_text, menus=menus))
cached_update_times[location] = datetime.now()
......
......@@ -28,6 +28,7 @@ from telegram.ext import (
from crawler import Day, Location, LocationDays, get_location_days
from database import (
CURITIBA_TZ,
delete_all_schedules_from_user,
delete_menu_item_indicator_preference,
delete_schedule_by_key,
......@@ -125,7 +126,7 @@ def format_location_days(location_days, visible_menu_item_indicators):
strings.append(
"<i>Atualizado às "
+ update_datetime.strftime("%H:%M:%S")
+ update_datetime.astimezone(CURITIBA_TZ).strftime("%H:%M:%S")
+ " de hoje</i>"
)
return "\n\n".join(strings)
......@@ -862,7 +863,7 @@ def try_send_schedule_again(context: CallbackContext) -> None:
def send_scheduled(context: CallbackContext) -> None:
dt = datetime.now()
dt = datetime.now(tz=CURITIBA_TZ)
dt += timedelta(minutes=EVERY_X_MINUTES / 2)
dt -= timedelta(
minutes=dt.minute % EVERY_X_MINUTES,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment