Add option to query latest bookable date
This commit is contained in:
parent
cf968da148
commit
823451f00a
1 changed files with 19 additions and 1 deletions
|
|
@ -1,7 +1,8 @@
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from typing import Annotated, Any
|
from typing import Annotated, Any
|
||||||
|
|
@ -287,6 +288,13 @@ def query(
|
||||||
return prices
|
return prices
|
||||||
|
|
||||||
|
|
||||||
|
def query_max_booking_date(endpoint: str = "/nj-booking-ocp/init/start") -> date | None:
|
||||||
|
latest_date = request_start().get("maxBookableDate")
|
||||||
|
if not latest_date:
|
||||||
|
return None
|
||||||
|
return date.fromisoformat(latest_date)
|
||||||
|
|
||||||
|
|
||||||
## CLI
|
## CLI
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
|
|
||||||
|
|
@ -330,7 +338,17 @@ def main(
|
||||||
dump_price_snapshot: bool = typer.Option(
|
dump_price_snapshot: bool = typer.Option(
|
||||||
True, help="Dump _all_ queried prices into a timestamped csv file."
|
True, help="Dump _all_ queried prices into a timestamped csv file."
|
||||||
),
|
),
|
||||||
|
latest_bookable_date: bool = typer.Option(
|
||||||
|
False, help="Check for latest currently possible booking date only."
|
||||||
|
),
|
||||||
):
|
):
|
||||||
|
if latest_bookable_date:
|
||||||
|
latest_date = query_max_booking_date()
|
||||||
|
if not latest_date:
|
||||||
|
dprint("Could not determine max bookable date.")
|
||||||
|
dprint(f"Latest currently bookable date: {latest_date}")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
base_output_directory.mkdir(exist_ok=True, parents=True)
|
base_output_directory.mkdir(exist_ok=True, parents=True)
|
||||||
lowest_prices_path = base_output_directory.joinpath(lowest_prices_filename)
|
lowest_prices_path = base_output_directory.joinpath(lowest_prices_filename)
|
||||||
price_snapshot_path = base_output_directory.joinpath(price_snapshot_pattern)
|
price_snapshot_path = base_output_directory.joinpath(price_snapshot_pattern)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue