File size: 3,597 Bytes
5bfc765
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
"""
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")