from tennis import get_time_slots, get_club_address import argparse from configparser import ConfigParser from pathlib import Path from weather import WeatherAPI import asyncio as aio import time from combo import get_decent_timeslots def existing_path(path_str): path = Path(path_str) if not path.exists() or not path.is_file(): raise argparse.ArgumentTypeError("Config file doesn't exist or isn't a file.") return path async def main(): parser = argparse.ArgumentParser() parser.add_argument( "-c", "--config-file", help="Path to config file.", default="padel.ini", type=existing_path, ) parser.add_argument( "-d", "--days", help="How many days in advance to look.", default=1, type=int ) parser.add_argument("club_id", help="ID of the club to check.", type=int) args = parser.parse_args() # Read config file config = ConfigParser() # TODO check if config file can be read config.read(args.config_file) res = await get_decent_timeslots( args.club_id, config["DEFAULT"]["weather_api_key"], args.days ) 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("%Y-%m-%d %H:%M"), int(duration.total_seconds() // 60), " -> ".join(pruned_weather_names) )) if __name__ == "__main__": aio.run(main())