Skip to content

Commit

Permalink
Add a script for running runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Krainski committed Jul 15, 2024
1 parent 02f626c commit 3c6f441
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
!.vscode/launch.json
!.vscode/extensions.json
.history

runs/*
!runs/run.sh
19 changes: 19 additions & 0 deletions runs/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

IFS=$'\n'
for row in $(cat flights-to-scan.csv)
do
origin_airport_name=$(echo $row | cut -d "," -f 1)
origin_airport_code=$(echo $row | cut -d "," -f 2)
destination_airport_name=$(echo $row | cut -d "," -f 3)
destination_airport_code=$(echo $row | cut -d "," -f 4)
departure_date=$(echo $row | cut -d "," -f 5)
return_date=$(echo $row | cut -d "," -f 6)
echo "Running for: $origin_airport_name $origin_airport_code $destination_airport_name $destination_airport_code $departure_date $return_date..."
poetry -C ../yafs run yafs \
--origin-airport $origin_airport_name $origin_airport_code \
--destination-airport $destination_airport_name $destination_airport_code \
--departure-date "$departure_date" \
--return-date "$return_date"
echo "Done."
done
30 changes: 29 additions & 1 deletion yafs/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions yafs/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python = "^3.12"
pytest = "^8.2.2"
playwright = "^1.45.0"
click = "^8.1.7"
python-slugify = "^8.0.4"


[tool.poetry.group.dev.dependencies]
Expand All @@ -34,6 +35,9 @@ ipython = "^8.26.0"
jupyter = "^1.0.0"
pytest-asyncio = "^0.23.7"

[tool.poetry.scripts]
yafs = 'yafs.main:yafs'

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Expand Down
25 changes: 22 additions & 3 deletions yafs/yafs/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import asyncio
import json
from functools import wraps

import click
from slugify import slugify

from yafs.flights import get_flights

Expand Down Expand Up @@ -37,12 +39,21 @@ def wrapper(*args, **kwargs):
)
@click.option("--departure-date", required=True)
@click.option("--return-date", required=True)
@click.option(
"--result-filename",
required=False,
help=(
"Results will be stored in this file. If not provided, a combination of "
"parameter names will be used"
),
)
@as_coroutine
async def command(
async def yafs(
origin_airport,
destination_airport,
departure_date,
return_date,
result_filename,
):
data = await get_flights(
origin_airport[0],
Expand All @@ -52,8 +63,16 @@ async def command(
departure_date,
return_date,
)
print(data)

if result_filename is None:
result_filename = (
f"{origin_airport[1]}-{destination_airport[1]}-{slugify(departure_date)}-"
f"{slugify(return_date)}.json"
)

with open(result_filename, "w") as f:
json.dump(data, f, indent=2)


if __name__ == "__main__":
command()
yafs()

0 comments on commit 3c6f441

Please sign in to comment.