- energy_thai.py: scrape Thai Oil (TOP) investor financial-highlights -> quarterly + annual EBITDA/Net Profit/Sales (Million Baht), largest Thai refinery - Thai-specific factor per user (energy must reflect Thai companies, not US EIA proxy); Krungsri was projection-only, TOP gives real quarterly actuals - Frequency: quarterly (documented in research note) - 4 tests; full backend suite 156 OK; compileall ok; static scan clean
30 lines
809 B
Python
30 lines
809 B
Python
"""Collect the Thai Energy/Refining factor (TOP quarterly financials) to JSON snapshot."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from datetime import datetime, timezone
|
|
|
|
from app import energy_thai
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--timeout", type=float, default=30.0)
|
|
args = parser.parse_args()
|
|
|
|
snap = energy_thai.fetch_energy_thai(timeout=args.timeout)
|
|
payload = {
|
|
"source": "thaioil",
|
|
"retrieved_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
"factor": "energy_thai",
|
|
"data": snap.to_dict(),
|
|
}
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, indent=2))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|