|
10 | 10 |
|
11 | 11 |
|
12 | 12 | classEtherscan: |
13 | | -def__new__(cls,api_key:str): |
14 | | -withresources.path(configs,"stable.json")aspath: |
| 13 | +def__new__(cls,api_key:str,net:str="MAIN"): |
| 14 | +withresources.path(configs,f"{net.upper()}-stable.json")aspath: |
15 | 15 | config_path=str(path) |
16 | | -returncls.from_config(api_key=api_key,config_path=config_path) |
| 16 | +returncls.from_config(api_key=api_key,config_path=config_path,net=net) |
17 | 17 |
|
18 | 18 | @staticmethod |
19 | 19 | def__load_config(config_path:str)->dict: |
20 | 20 | withopen(config_path,"r")asf: |
21 | 21 | returnjson.load(f) |
22 | 22 |
|
23 | 23 | @staticmethod |
24 | | -def__run(func,api_key:str): |
| 24 | +def__run(func,api_key:str,net:str): |
25 | 25 | defwrapper(*args,**kwargs): |
26 | 26 | url= ( |
27 | | -f"{fields.PREFIX}" |
| 27 | +f"{fields.PREFIX.format(net.lower()).replace('-main','')}" |
28 | 28 | f"{func(*args,**kwargs)}" |
29 | 29 | f"{fields.API_KEY}" |
30 | 30 | f"{api_key}" |
31 | 31 | ) |
32 | | -r=requests.get(url) |
| 32 | +r=requests.get(url,headers={'User-Agent':''}) |
33 | 33 | returnparser.parse(r) |
34 | 34 |
|
35 | 35 | returnwrapper |
36 | 36 |
|
37 | 37 | @classmethod |
38 | | -deffrom_config(cls,api_key:str,config_path:str): |
| 38 | +deffrom_config(cls,api_key:str,config_path:str,net:str): |
39 | 39 | config=cls.__load_config(config_path) |
40 | 40 | forfunc,vinconfig.items(): |
41 | 41 | ifnotfunc.startswith("_"):# disabled if _ |
42 | 42 | attr=getattr(getattr(etherscan,v["module"]),func) |
43 | | -setattr(cls,func,cls.__run(attr,api_key)) |
| 43 | +setattr(cls,func,cls.__run(attr,api_key,net)) |
44 | 44 | returncls |