padel/padel/__main__.py

50 lines
1.2 KiB
Python

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
)
print(res)
if __name__ == "__main__":
aio.run(main())