nice-bill commited on
Commit
d6f2ed2
·
1 Parent(s): 91f2ea1

multiple Dune keys support

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -11,13 +11,29 @@ import os
11
  import requests
12
  import uuid
13
  import time
 
14
  from dotenv import load_dotenv
15
  from diskcache import Cache
16
  from typing import Optional, Dict, Any
17
 
18
  # Load environment variables
19
  load_dotenv()
20
- DUNE_API_KEY = os.getenv("DUNE_API_KEY")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  # Initialize Limiter
23
  limiter = Limiter(key_func=get_remote_address)
@@ -91,12 +107,15 @@ def process_wallet_analysis(job_id: str, wallet_address: str):
91
  cache.set(job_id, {"status": "processing", "wallet": wallet_address}, expire=CACHE_TTL)
92
 
93
  # 1. Execute Dune Query (Start New Run)
94
- if not DUNE_API_KEY:
95
- raise Exception("Dune API Key missing configuration.")
 
 
 
96
 
97
  # Step A: Submit Execution
98
  execute_url = "https://api.dune.com/api/v1/query/6252521/execute"
99
- headers = {"X-Dune-API-Key": DUNE_API_KEY}
100
  payload = {"query_parameters": {"wallet": wallet_address}}
101
 
102
  print(f"Submitting Dune query for {wallet_address}...")
 
11
  import requests
12
  import uuid
13
  import time
14
+ import random
15
  from dotenv import load_dotenv
16
  from diskcache import Cache
17
  from typing import Optional, Dict, Any
18
 
19
  # Load environment variables
20
  load_dotenv()
21
+
22
+ # Load all available Dune API Keys
23
+ DUNE_API_KEYS = []
24
+ # 1. Primary Key
25
+ if os.getenv("DUNE_API_KEY"):
26
+ DUNE_API_KEYS.append(os.getenv("DUNE_API_KEY"))
27
+ # 2. Secondary Keys (DUNE_API_KEY_2, _3, etc.)
28
+ i = 2
29
+ while True:
30
+ key = os.getenv(f"DUNE_API_KEY_{i}")
31
+ if not key:
32
+ break
33
+ DUNE_API_KEYS.append(key)
34
+ i += 1
35
+
36
+ print(f"Loaded {len(DUNE_API_KEYS)} Dune API Keys.")
37
 
38
  # Initialize Limiter
39
  limiter = Limiter(key_func=get_remote_address)
 
107
  cache.set(job_id, {"status": "processing", "wallet": wallet_address}, expire=CACHE_TTL)
108
 
109
  # 1. Execute Dune Query (Start New Run)
110
+ if not DUNE_API_KEYS:
111
+ raise Exception("Dune API configuration missing.")
112
+
113
+ # Select a random API key to distribute load
114
+ selected_api_key = random.choice(DUNE_API_KEYS)
115
 
116
  # Step A: Submit Execution
117
  execute_url = "https://api.dune.com/api/v1/query/6252521/execute"
118
+ headers = {"X-Dune-API-Key": selected_api_key}
119
  payload = {"query_parameters": {"wallet": wallet_address}}
120
 
121
  print(f"Submitting Dune query for {wallet_address}...")