|
3 | 3 |
|
4 | 4 | """CLI tool to interact with the trading API.""" |
5 | 5 |
|
6 | | -import argparse |
7 | 6 | from datetime import datetime, timedelta |
8 | 7 | from zoneinfo import ZoneInfo |
9 | 8 |
|
| 9 | +import click |
| 10 | + |
10 | 11 | from frequenz.client.electricity_trading.cli.day_ahead import list_day_ahead_prices |
11 | 12 |
|
| 13 | +TZ = ZoneInfo("Europe/Berlin") |
12 | 14 |
|
13 | | -def main() -> None: |
14 | | - """Run main entry point for the CLI tool.""" |
15 | | - tz = ZoneInfo("Europe/Berlin") |
16 | | - midnight = datetime.combine(datetime.now(tz), datetime.min.time(), tzinfo=tz) |
17 | | - parser = argparse.ArgumentParser() |
18 | | - parser.add_argument("--entsoe_key", type=str, required=True) |
19 | | - parser.add_argument( |
20 | | - "--start", |
21 | | - type=datetime.fromisoformat, |
22 | | - required=False, |
23 | | - default=midnight, |
24 | | - ) |
25 | | - parser.add_argument( |
26 | | - "--end", |
27 | | - type=datetime.fromisoformat, |
28 | | - required=False, |
29 | | - default=midnight + timedelta(days=2), |
30 | | - ) |
31 | | - parser.add_argument("--country_code", type=str, required=False, default="DE_LU") |
32 | | - args = parser.parse_args() |
| 15 | +iso = datetime.fromisoformat |
| 16 | + |
| 17 | + |
| 18 | +def midnight(days: int = 0) -> str: |
| 19 | + """Return today's midnight.""" |
| 20 | + return ( |
| 21 | + datetime.combine(datetime.now(TZ), datetime.min.time(), tzinfo=TZ) |
| 22 | + + timedelta(days) |
| 23 | + ).isoformat() |
33 | 24 |
|
| 25 | + |
| 26 | +@click.group() |
| 27 | +def cli() -> None: |
| 28 | + """CLI tool to interact with the trading API.""" |
| 29 | + |
| 30 | + |
| 31 | +@cli.command() |
| 32 | +@click.option("--entsoe-key", required=True, type=str) |
| 33 | +@click.option("--start", default=midnight(), type=iso) |
| 34 | +@click.option("--end", default=midnight(days=2), type=iso) |
| 35 | +@click.option("--country-code", type=str, default="DE_LU") |
| 36 | +def list_day_ahead( |
| 37 | + entsoe_key: str, *, start: datetime, end: datetime, country_code: str |
| 38 | +) -> None: |
| 39 | + """List day-ahead prices.""" |
34 | 40 | list_day_ahead_prices( |
35 | | - entsoe_key=args.entsoe_key, |
36 | | - start=args.start, |
37 | | - end=args.end, |
38 | | - country_code=args.country_code, |
| 41 | + entsoe_key=entsoe_key, start=start, end=end, country_code=country_code |
39 | 42 | ) |
40 | 43 |
|
41 | 44 |
|
| 45 | +def main() -> None: |
| 46 | + """Run the main Click CLI.""" |
| 47 | + cli() |
| 48 | + |
| 49 | + |
42 | 50 | if __name__ == "__main__": |
43 | 51 | main() |
0 commit comments