Spaces:
Running
Running
File size: 1,116 Bytes
3972bf0 | 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 | import sys
import os
from dotenv import load_dotenv
# Ensure backend directory is in the system path for imports
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
# Load environmental configurations
load_dotenv()
from app.services.agmarknet_api import fetch_agmarknet_mandi_prices
from app.database import MandiSessionLocal
if __name__ == "__main__":
print("[Mandi CLI Fetcher] Triggering manual daily Mandi price fetch...")
db = MandiSessionLocal()
try:
# Check for target_date from CLI argument
target_date = sys.argv[1] if len(sys.argv) > 1 else None
if target_date:
print(f"[Mandi CLI Fetcher] Querying target date: {target_date}")
# Executes the parallelized, retrying, browser-authenticated agmarknet API fetcher
fetch_agmarknet_mandi_prices(db=db, target_date=target_date)
print("[Mandi CLI Fetcher] Fetch and rolling cleanup completed successfully.")
except Exception as e:
print(f"[Mandi CLI Fetcher] CRITICAL: Execution failed: {e}", file=sys.stderr)
sys.exit(1)
finally:
db.close()
|