File size: 3,833 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
Batch fix all 48 scripts to:
1. Skip API calls
2. Use existing round 1253 data
"""
import os
from pathlib import Path

scripts_dir = Path("c:/numerai48models/scripts")

# All script paths to fix
script_patterns = [
    "main/*.py",
    "main_v2/*.py", 
    "main_v3/*.py",
    "main_nlp/*.py",
    "main_ultimate/*.py",
    "signals/*.py",
    "signals_v2/*.py",
    "signals_v3/*.py", 
    "signals_nlp/*.py",
    "signals_ultimate/*.py",
    "crypto/*.py",
    "crypto_v3/*.py",
    "crypto_nlp/*.py",
    "3tournaments_main/*.py",
    "3tournaments_signals/*.py",
    "3tournaments_crypto/*.py",
    "3tournaments_crypto_v2/*.py"
]

all_scripts = []
for pattern in script_patterns:
    all_scripts.extend(scripts_dir.glob(pattern))

patched = 0
for script in all_scripts:
    try:
        with open(script, 'r', encoding='utf-8', errors='ignore') as f:
            content = f.read()
        
        if 'SKIP_API' in content:
            continue  # Already patched
        
        # Patch 1: Add SKIP_API check before NumerAPI
        old1 = 'napi = NumerAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'
        new1 = '''SKIP_API = os.getenv('SKIP_API_CALLS', 'false').lower() == 'true'
if SKIP_API:
    print("[SKIP_API] Using existing data")
    napi = None
    current_round = 1253
else:
    napi = NumerAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'''
        
        if old1 in content:
            content = content.replace(old1, new1, 1)
        
        # Patch 2: Same for SignalsAPI
        old2 = 'sapi = SignalsAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'
        new2 = '''SKIP_API = os.getenv('SKIP_API_CALLS', 'false').lower() == 'true'
if SKIP_API:
    print("[SKIP_API] Using existing data")
    sapi = None
    current_round = 1253
else:
    sapi = SignalsAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'''
        
        if old2 in content:
            content = content.replace(old2, new2, 1)
        
        # Patch 3: Same for CryptoAPI
        old3 = 'capi = CryptoAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'
        new3 = '''SKIP_API = os.getenv('SKIP_API_CALLS', 'false').lower() == 'true'
if SKIP_API:
    print("[SKIP_API] Using existing data")
    capi = None
    current_round = 1253
else:
    capi = CryptoAPI(public_id=NUMERAI_PUBLIC_ID, secret_key=NUMERAI_SECRET_KEY)'''
        
        if old3 in content:
            content = content.replace(old3, new3, 1)
        
        # Patch 4: Skip get_current_round calls
        content = content.replace(
            'current_round = napi.get_current_round()',
            'current_round = 1253 if SKIP_API else napi.get_current_round()'
        )
        content = content.replace(
            'current_round = sapi.get_current_round()',
            'current_round = 1253 if SKIP_API else sapi.get_current_round()'
        )
        content = content.replace(
            'current_round = capi.get_current_round()',
            'current_round = 1253 if SKIP_API else capi.get_current_round()'
        )
        
        # Patch 5: Skip downloads
        content = content.replace(
            'napi.download_dataset(',
            'napi.download_dataset( if not SKIP_API else print("  [SKIP_API] Skip download") or ('
        )
        content = content.replace(
            'sapi.download_dataset(',
            'sapi.download_dataset( if not SKIP_API else print("  [SKIP_API] Skip download") or ('
        )
        
        with open(script, 'w', encoding='utf-8', errors='ignore') as f:
            f.write(content)
        
        print(f"[OK] {script.relative_to(scripts_dir)}")
        patched += 1
        
    except Exception as e:
        print(f"[ERR] {script.name}: {e}")

print(f"\nPatched {patched}/{len(all_scripts)} scripts!")