섹터 유니버스 분리와 월간 갱신 정합화
This commit is contained in:
@@ -3,6 +3,7 @@ import os
|
||||
import requests
|
||||
import time
|
||||
import subprocess
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
@@ -10,6 +11,7 @@ CLASPRC_PATH = ROOT / ".clasprc.json"
|
||||
CLASP_PATH = ROOT / ".clasp.json"
|
||||
SPREADSHEET_ID = "1e1TNlLfnT69nvw-I1wU_oBHmEtI2pfbld3e0fFmtrZM"
|
||||
OUTPUT_XLSX = ROOT / "GatherTradingData.xlsx"
|
||||
LOCAL_OUTPUT_XLSX = ROOT / "outputs" / "sector_insights_enhanced" / "GatherTradingData_sector_insights.xlsx"
|
||||
|
||||
def get_tokens():
|
||||
if not CLASPRC_PATH.exists():
|
||||
@@ -75,20 +77,46 @@ def download_spreadsheet(spreadsheet_id, access_token, output_path):
|
||||
print(f"Successfully downloaded to {output_path}")
|
||||
return True
|
||||
|
||||
def validate_monthly_sector_refresh(xlsx_path: Path) -> bool:
|
||||
cmd = [
|
||||
"python",
|
||||
"tools/validate_sector_universe_monthly_refresh_v1.py",
|
||||
"--xlsx",
|
||||
str(xlsx_path),
|
||||
]
|
||||
print(f"Validating monthly sector refresh: {xlsx_path} ...")
|
||||
res = subprocess.run(cmd, cwd=str(ROOT))
|
||||
if res.returncode == 0:
|
||||
print("Monthly sector refresh validation passed.")
|
||||
return True
|
||||
print("Monthly sector refresh validation failed.")
|
||||
return False
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--function", default="runDataFeed", help="Primary GAS function to execute before download")
|
||||
parser.add_argument("--fallback-function", default="run_all", help="Fallback GAS function to execute if primary fails")
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
tokens = get_tokens()
|
||||
script_id = get_script_id()
|
||||
access_token = refresh_access_token(tokens)
|
||||
|
||||
# Step 1: Execute GAS run_all
|
||||
if run_gas_function(script_id, access_token, "run_all"):
|
||||
# Step 1: Execute GAS runDataFeed first, then fallback to run_all if needed.
|
||||
primary_ok = run_gas_function(script_id, access_token, args.function)
|
||||
if not primary_ok and args.fallback_function and args.fallback_function != args.function:
|
||||
print(f"Primary function {args.function} failed; trying fallback {args.fallback_function} ...")
|
||||
primary_ok = run_gas_function(script_id, access_token, args.fallback_function)
|
||||
|
||||
if primary_ok:
|
||||
print("Waiting a bit for GAS processes to finalize (optional)...")
|
||||
time.sleep(5)
|
||||
|
||||
# Step 2: Download spreadsheet
|
||||
if download_spreadsheet(SPREADSHEET_ID, access_token, OUTPUT_XLSX):
|
||||
print("\nRoutine Part 1 & 2 complete.")
|
||||
validate_monthly_sector_refresh(OUTPUT_XLSX)
|
||||
print("Final step: npm run prepare-upload-zip")
|
||||
else:
|
||||
print("\nDownload failed. Please check Drive API scopes.")
|
||||
@@ -98,6 +126,7 @@ def main():
|
||||
fallback = subprocess.run(["python", "tools/update_workbook_sector_insights.py"], cwd=str(ROOT))
|
||||
if fallback.returncode == 0:
|
||||
print("Local sector-insight workbook updated.")
|
||||
validate_monthly_sector_refresh(LOCAL_OUTPUT_XLSX)
|
||||
else:
|
||||
print("Local sector-insight workbook build failed.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user