-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect_forecasts.py
More file actions
142 lines (111 loc) · 3.65 KB
/
collect_forecasts.py
File metadata and controls
142 lines (111 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env python3
"""BOM Weather Tracker - Forecast Collection Script.
This script collects weather forecasts from the Australian Bureau of
Meteorology (BOM) FTP server for all configured locations and stores
them in Git-friendly JSON files.
Usage:
python collect_forecasts.py [--config CONFIG_PATH] [--data DATA_DIR]
Arguments:
--config Path to locations.json configuration file (default: data/locations.json)
--data Base directory for data files (default: data)
Requirements: 2.1
"""
import argparse
import logging
import sys
from datetime import date
from pathlib import Path
from zoneinfo import ZoneInfo
from src.collector import collect_forecasts
from src.utils import setup_logging
def get_aedt_date() -> date:
"""Get current date in Australian Eastern Daylight Time (AEDT).
Returns:
Current date in AEDT timezone
"""
from datetime import datetime
# Get current time in AEDT
aedt_tz = ZoneInfo("Australia/Sydney")
aedt_now = datetime.now(aedt_tz)
return aedt_now.date()
def parse_args() -> argparse.Namespace:
"""Parse command line arguments.
Returns:
Parsed arguments namespace
"""
parser = argparse.ArgumentParser(
description="Collect weather forecasts from BOM FTP server",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Run with default paths
python collect_forecasts.py
# Specify custom config and data paths
python collect_forecasts.py --config /path/to/locations.json --data /path/to/data
""",
)
parser.add_argument(
"--config",
type=Path,
default=Path("dashboard/public/data/locations.json"),
help="Path to locations.json configuration file (default: dashboard/public/data/locations.json)",
)
parser.add_argument(
"--data",
type=Path,
default=Path("dashboard/public/data"),
help="Base directory for data files (default: dashboard/public/data)",
)
parser.add_argument(
"--verbose", "-v",
action="store_true",
help="Enable verbose (debug) logging",
)
parser.add_argument(
"--city",
type=str,
default=None,
help="Filter to a single city name (e.g., 'Sydney')",
)
return parser.parse_args()
def main() -> int:
"""Main entry point for forecast collection.
Returns:
Exit code: 0 for success, 1 for partial failure, 2 for complete failure
"""
args = parse_args()
# Configure logging level
logger = setup_logging()
if args.verbose:
logger.setLevel(logging.DEBUG)
# Get current date in AEDT
aedt_date = get_aedt_date()
logger.info(f"Using AEDT date: {aedt_date}")
# Run collection with explicit AEDT date
result = collect_forecasts(
config_path=args.config,
data_dir=args.data,
collection_date=aedt_date,
city_filter=args.city,
)
# Report results
if result.total == 0:
print("No locations to process")
return 2
print(f"\nCollection Summary:")
print(f" Total locations: {result.total}")
print(f" Successes: {result.successes}")
print(f" Failures: {result.failures}")
if result.failures > 0:
print(f"\nFailed locations:")
for error in result.errors:
print(f" - {error}")
# Return appropriate exit code
if result.failures == result.total:
return 2 # Complete failure
elif result.failures > 0:
return 1 # Partial failure
else:
return 0 # Success
if __name__ == "__main__":
sys.exit(main())