numerai_all_48_models / PATCH_ALL_SCRIPTS.py
dirven's picture
Upload folder using huggingface_hub
5bfc765 verified
Raw History Blame Contribute Delete
3.6 kB
"""
Patch all 48 scripts to skip API calls and use existing data
"""
import os
from pathlib import Path
scripts_dir = Path("c:/numerai48models/scripts")
# Find all Python scripts
all_scripts = list(scripts_dir.rglob("*.py"))
patch_count = 0
for script_path in all_scripts:
try:
with open(script_path, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
modified = False
# Skip if already patched
if 'SKIP_API_CALLS' in content:
continue
# Patch: Skip get_current_round() API call
if 'napi.get_current_round()' in content or 'api.get_current_round()' in content:
# Add environment check at the top of the API section
old_api = 'napi = NumerAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'
new_api = '''# SKIP_API_CALLS - Use existing data without API calls
SKIP_API = os.getenv('SKIP_API_CALLS', 'true').lower() == 'true'
napi = NumerAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY) if not SKIP_API else None'''
if old_api in content:
content = content.replace(old_api, new_api)
modified = True
# Skip get_current_round
old_round = '''try:
current_round = napi.get_current_round()
print(f" Current round: {current_round}")
except Exception as e:
print(f" [WARNING] Could not get current round: {e}")
print(" Proceeding with download anyway...")
current_round = None'''
new_round = '''if SKIP_API:
current_round = 1253 # Use existing round 1253 data
print(f" [SKIP_API] Using round: {current_round}")
else:
try:
current_round = napi.get_current_round()
print(f" Current round: {current_round}")
except Exception as e:
print(f" [WARNING] Could not get current round: {e}")
print(" Proceeding with download anyway...")
current_round = None'''
if old_round in content:
content = content.replace(old_round, new_round)
modified = True
# Skip download
old_download = 'napi.download_dataset("v5.2/live.parquet", str(live_path))'
new_download = '''if not SKIP_API:
napi.download_dataset("v5.2/live.parquet", str(live_path))
else:
print(" [SKIP_API] Using existing data file")'''
if old_download in content:
content = content.replace(old_download, new_download)
modified = True
# Similar for SignalsAPI
if 'SignalsAPI(public_id' in content:
old_sig = 'sapi = SignalsAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'
new_sig = '''SKIP_API = os.getenv('SKIP_API_CALLS', 'true').lower() == 'true'
sapi = SignalsAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY) if not SKIP_API else None'''
if old_sig in content:
content = content.replace(old_sig, new_sig)
modified = True
if modified:
with open(script_path, 'w', encoding='utf-8', errors='ignore') as f:
f.write(content)
print(f"[OK] Patched: {script_path.relative_to(scripts_dir)}")
patch_count += 1
except Exception as e:
print(f"[ERROR] {script_path.name}: {e}")
print(f"\nPatched {patch_count} scripts!")
print("Set environment variable: SKIP_API_CALLS=true")