padel/padel/__main__.py

47 lines
1.4 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
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
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)
club_address = get_club_address(args.club_id)
if club_address is None:
print("Couldn't get club address.")
return
weather_api = WeatherAPI(config["DEFAULT"]["weather_api_key"])
weather_forecasts = weather_api.get_hourly_conditions(club_address,
days=args.days)
timeslots = get_time_slots(args.club_id, days=args.days)
if __name__ == "__main__":
main()