Spaces:
Runtime error
Runtime error
gauravlochab
commited on
Commit
·
3893ff1
1
Parent(s):
c1b9444
feat: Add delay between API requests for block retrieval
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import plotly.express as px
|
|
5 |
from datetime import datetime, timedelta
|
6 |
import json
|
7 |
from web3 import Web3
|
8 |
-
|
9 |
# RPC URLs
|
10 |
OPTIMISM_RPC_URL = 'https://opt-mainnet.g.alchemy.com/v2/U5gnXPYxeyH43MJ9tP8ONBQHEDRav7H0'
|
11 |
BASE_RPC_URL = 'https://base-mainnet.g.alchemy.com/v2/U5gnXPYxeyH43MJ9tP8ONBQHEDRav7H0'
|
@@ -80,6 +80,7 @@ def get_block_range_for_date(chain_id, date_str, api_key, base_url):
|
|
80 |
end_timestamp = int(end_of_day.timestamp())
|
81 |
|
82 |
# Get start block
|
|
|
83 |
start_response = requests.get(
|
84 |
f"{base_url}?module=block&action=getblocknobytime×tamp={start_timestamp}&closest=before&apikey={api_key}"
|
85 |
)
|
@@ -96,6 +97,7 @@ def get_block_range_for_date(chain_id, date_str, api_key, base_url):
|
|
96 |
print(f"Start block for chain {chain_id} on {date_str}: {start_block}")
|
97 |
|
98 |
# Get end block
|
|
|
99 |
end_response = requests.get(
|
100 |
f"{base_url}?module=block&action=getblocknobytime×tamp={end_timestamp}&closest=before&apikey={api_key}"
|
101 |
)
|
@@ -137,6 +139,9 @@ def get_transactions(api_keys, wallet_address, chain_name, start_block, end_bloc
|
|
137 |
|
138 |
response = requests.get(base_url, params=params)
|
139 |
data = response.json()
|
|
|
|
|
|
|
140 |
if data['status'] != '1':
|
141 |
print(f"Error: {data['message']}")
|
142 |
return []
|
|
|
5 |
from datetime import datetime, timedelta
|
6 |
import json
|
7 |
from web3 import Web3
|
8 |
+
import time
|
9 |
# RPC URLs
|
10 |
OPTIMISM_RPC_URL = 'https://opt-mainnet.g.alchemy.com/v2/U5gnXPYxeyH43MJ9tP8ONBQHEDRav7H0'
|
11 |
BASE_RPC_URL = 'https://base-mainnet.g.alchemy.com/v2/U5gnXPYxeyH43MJ9tP8ONBQHEDRav7H0'
|
|
|
80 |
end_timestamp = int(end_of_day.timestamp())
|
81 |
|
82 |
# Get start block
|
83 |
+
|
84 |
start_response = requests.get(
|
85 |
f"{base_url}?module=block&action=getblocknobytime×tamp={start_timestamp}&closest=before&apikey={api_key}"
|
86 |
)
|
|
|
97 |
print(f"Start block for chain {chain_id} on {date_str}: {start_block}")
|
98 |
|
99 |
# Get end block
|
100 |
+
time.sleep(1)
|
101 |
end_response = requests.get(
|
102 |
f"{base_url}?module=block&action=getblocknobytime×tamp={end_timestamp}&closest=before&apikey={api_key}"
|
103 |
)
|
|
|
139 |
|
140 |
response = requests.get(base_url, params=params)
|
141 |
data = response.json()
|
142 |
+
|
143 |
+
time.sleep(1)
|
144 |
+
|
145 |
if data['status'] != '1':
|
146 |
print(f"Error: {data['message']}")
|
147 |
return []
|