30 lines
914 B
Python
30 lines
914 B
Python
from tennis import get_time_slots, get_club_address
|
|
from weather import WeatherAPI
|
|
import asyncio as aio
|
|
|
|
|
|
# Provided by my code monkey Lander
|
|
GOOD_CODES = [1000,1003, 1006, 1009,1150, 1153]
|
|
|
|
|
|
async def get_decent_timeslots(club_id, weather_api_key, days=1):
|
|
club_address = await get_club_address(club_id)
|
|
|
|
if club_address is None:
|
|
return None
|
|
|
|
weather_api = WeatherAPI(weather_api_key)
|
|
weather_forecasts, timeslots = await aio.gather(
|
|
weather_api.get_hourly_conditions(club_address, days=days),
|
|
get_time_slots(club_id, days=days)
|
|
)
|
|
|
|
# Filter out bad weather forecasts & sort them according to date & time
|
|
weather_forecasts = sorted(filter(lambda x: x[2] in GOOD_CODES,
|
|
weather_forecasts), key=lambda x: x[0])
|
|
|
|
# Filter out non-free timeslots
|
|
timeslots = filter(lambda x: x[1] == 0, timeslots)
|
|
|
|
return timeslots
|