padel/padel/__main__.py

50 lines
1.4 KiB
Python
Raw Normal View History

2021-08-11 13:55:39 +02:00
from tennis import get_time_slots, get_club_address
import argparse
from configparser import ConfigParser
from pathlib import Path
from weather import WeatherAPI
2021-08-11 15:48:03 +02:00
import asyncio as aio
import time
2021-08-11 13:55:39 +02:00
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
2021-08-11 15:48:03 +02:00
async def main():
2021-08-11 13:55:39 +02:00
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)
2021-08-11 15:48:03 +02:00
club_address = await get_club_address(args.club_id)
2021-08-11 13:55:39 +02:00
if club_address is None:
print("Couldn't get club address.")
return
weather_api = WeatherAPI(config["DEFAULT"]["weather_api_key"])
2021-08-11 15:48:03 +02:00
weather_forecasts, timeslots = await aio.gather(
weather_api.get_hourly_conditions(club_address, days=args.days),
get_time_slots(args.club_id, days=args.days)
)
2021-08-11 13:55:39 +02:00
if __name__ == "__main__":
2021-08-11 15:48:03 +02:00
aio.run(main())