-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_econ.py
More file actions
93 lines (73 loc) · 2.69 KB
/
Copy pathrun_econ.py
File metadata and controls
93 lines (73 loc) · 2.69 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
"""
run_econ.py – Economic adjustment layer entry point.
Usage:
python run_econ.py fetch # refresh indicators into econ_indicators
python run_econ.py fetch --source hcp # only try HCP-backed chain steps
python run_econ.py apply # build *_real tables from econ_indicators
python run_econ.py all # fetch + apply
"""
from __future__ import annotations
import argparse
import logging
import sys
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parent
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
from dotenv import load_dotenv
from config.settings import LOG_DIR, LOG_FILE, LOG_LEVEL
from econ.apply import apply_all
from econ.fetcher import fetch_all, load_econ_indicators_to_sqlite
def setup_logging() -> None:
LOG_DIR.mkdir(parents=True, exist_ok=True)
logging.basicConfig(
level=getattr(logging, LOG_LEVEL, logging.INFO),
format="%(asctime)s %(levelname)-8s %(name)s %(message)s",
handlers=[
logging.FileHandler(LOG_FILE, encoding="utf-8"),
logging.StreamHandler(sys.stdout),
],
)
def main() -> None:
load_dotenv(PROJECT_ROOT / ".env")
parser = argparse.ArgumentParser(description="Economic adjustment layer")
sub = parser.add_subparsers(dest="cmd", required=True)
p_fetch = sub.add_parser("fetch", help="Download macro series and refresh econ_indicators")
p_fetch.add_argument(
"--source",
type=str,
default=None,
help="Only run chain steps for this source label (e.g. hcp, fred, worldbank, bam)",
)
sub.add_parser("apply", help="Build *_real tables from SQLite + econ_indicators")
p_all = sub.add_parser("all", help="fetch then apply")
p_all.add_argument(
"--source",
type=str,
default=None,
help="Only run chain steps for this source label (e.g. hcp, fred, worldbank, bam)",
)
args = parser.parse_args()
setup_logging()
log = logging.getLogger("econ")
if args.cmd == "fetch":
log.info("ECON FETCH start")
df = fetch_all(source_filter=args.source)
load_econ_indicators_to_sqlite(df)
log.info("ECON FETCH done (%d indicator rows)", len(df))
return
if args.cmd == "apply":
log.info("ECON APPLY start")
apply_all()
log.info("ECON APPLY done")
return
if args.cmd == "all":
log.info("ECON ALL start (fetch)")
df = fetch_all(source_filter=args.source)
load_econ_indicators_to_sqlite(df)
log.info("ECON ALL apply")
apply_all()
log.info("ECON ALL done")
return
if __name__ == "__main__":
main()