11import json
2+ from importlib import resources
23
34import requests
45
56import etherscan
7+ from etherscan import configs
68from etherscan .enums .fields_enum import FieldsEnum as fields
79from etherscan .utils .parsing import ResponseParser as parser
810
911
1012class Etherscan :
13+ def __new__ (cls ,api_key :str ):
14+ with resources .path (configs ,"stable.json" )as path :
15+ config_path = str (path )
16+ return cls .from_config (api_key = api_key ,config_path = config_path )
17+
1118@staticmethod
1219def __load_config (config_path :str )-> dict :
1320with open (config_path ,"r" )as f :
1421return json .load (f )
1522
1623@staticmethod
17- def __run (func ,api_key ):
24+ def __run (func ,api_key : str ):
1825def wrapper (* args ,** kwargs ):
1926url = (
2027f"{ fields .PREFIX } "
@@ -28,7 +35,7 @@ def wrapper(*args, **kwargs):
2835return wrapper
2936
3037@classmethod
31- def from_config (cls ,config_path :str ,api_key :str ):
38+ def from_config (cls ,api_key :str ,config_path :str ):
3239config = cls .__load_config (config_path )
3340for func ,v in config .items ():
3441if not func .startswith ("_" ):# disabled if _