From 56ff5d4cc31b1c1c280a2fd5cbfdfb7e107ecb30 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 11 Aug 2021 17:27:11 +0200 Subject: [PATCH 1/2] Added better cli output --- padel/__main__.py | 10 +++++++++- padel/combo.py | 2 -- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/padel/__main__.py b/padel/__main__.py index 9d8e899..99fa063 100644 --- a/padel/__main__.py +++ b/padel/__main__.py @@ -42,7 +42,15 @@ async def main(): args.club_id, config["DEFAULT"]["weather_api_key"], args.days ) - print(res) + for field_name, start_time, duration, weather_names in res: + pruned_weather_names = sorted(set(weather_names), + key=lambda x: weather_names.index(x)) + print("{} ({}, {}m): {}".format( + field_name, + start_time.strftime("%d:%m:%y %H:%M"), + int(duration.total_seconds() // 60), + " -> ".join(pruned_weather_names) + )) if __name__ == "__main__": diff --git a/padel/combo.py b/padel/combo.py index 8d16cfd..42483f6 100644 --- a/padel/combo.py +++ b/padel/combo.py @@ -29,11 +29,9 @@ async def get_decent_timeslots(club_id, weather_api_key, days=1): weather_forecasts = { date_obj: weather_str for date_obj, weather_str, _ in weather_forecasts } - print(weather_forecasts) # Filter out non-free timeslots timeslots = list(filter(lambda x: x[1] == 0, timeslots)) - print(timeslots) output = [] From dafc04a109b4a08baa506bfec4671769eef91c05 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Wed, 11 Aug 2021 17:43:49 +0200 Subject: [PATCH 2/2] Small changes --- padel/__main__.py | 4 +++- padel/combo.py | 7 ++++--- padel/tennis.py | 4 +--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/padel/__main__.py b/padel/__main__.py index 99fa063..1eb8e5b 100644 --- a/padel/__main__.py +++ b/padel/__main__.py @@ -43,11 +43,13 @@ async def main(): ) for field_name, start_time, duration, weather_names in res: + # Very satisfying, create a set & sort it using the original list's index pruned_weather_names = sorted(set(weather_names), key=lambda x: weather_names.index(x)) + print("{} ({}, {}m): {}".format( field_name, - start_time.strftime("%d:%m:%y %H:%M"), + start_time.strftime("%Y-%m-%d %H:%M"), int(duration.total_seconds() // 60), " -> ".join(pruned_weather_names) )) diff --git a/padel/combo.py b/padel/combo.py index 42483f6..2b396cd 100644 --- a/padel/combo.py +++ b/padel/combo.py @@ -1,6 +1,6 @@ from tennis import get_time_slots, get_club_address from weather import WeatherAPI -from datetime import timedelta +from datetime import timedelta, datetime import asyncio as aio @@ -30,8 +30,9 @@ async def get_decent_timeslots(club_id, weather_api_key, days=1): date_obj: weather_str for date_obj, weather_str, _ in weather_forecasts } - # Filter out non-free timeslots - timeslots = list(filter(lambda x: x[1] == 0, timeslots)) + # Filter out non-free timeslots or timeslots in the past + now = datetime.now() + timeslots = list(filter(lambda x: x[1] == 0 and x[2] > now, timeslots)) output = [] diff --git a/padel/tennis.py b/padel/tennis.py index 823339a..b021495 100644 --- a/padel/tennis.py +++ b/padel/tennis.py @@ -13,9 +13,7 @@ def extract_timeslots(tbody, column_headers): for tr in tbody.findAll("tr"): # Determine time for row - time_str = tr.find("th").text - hour, minute = map(int, time_str.split(":")) - start_time = time(hour=hour, minute=minute) + start_time = time.fromisoformat(tr.find("th").text) # Iterate over each column for td in tr.findAll("td"):