-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgen_subgraph_urls.py
42 lines (34 loc) · 1.15 KB
/
gen_subgraph_urls.py
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
import json
import os
import requests
from bal_tools.subgraph import Subgraph
def main():
# make sure that if thegraph api key somehow finds its way into the env that it is wiped
os.environ["GRAPH_API_KEY"] = ""
urls = {}
with open("extras/chains.json", "r") as f:
chains = json.load(f)
for chain in chains["CHAIN_IDS_BY_NAME"]:
if chain not in urls:
urls[chain] = {}
for subgraph_type in ["core", "gauges", "blocks", "aura"]:
subgraph = Subgraph(chain)
try:
url = subgraph.get_subgraph_url(subgraph_type)
except:
continue
if url:
print(url)
code = requests.get(url).status_code
if code == 200:
urls[chain].update({subgraph_type: url})
else:
urls[chain].update({subgraph_type: {code: url}})
else:
continue
# dump the collected dict to json file
with open("outputs/subgraph_urls.json", "w") as f:
json.dump(urls, f, indent=2)
f.write("\n")
if __name__ == "__main__":
main()