

from base_class import BaseVariableFunction
from base_class import *
baseclass = BaseVariableFunction(__file__)

old_print = print
 

def timestamped_print(*args, **kwargs):
    old_print(datetime.datetime.utcnow().replace(
        microsecond=0), *args, **kwargs)

 

print = timestamped_print
print('\n'*5)
print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")

def  get_one_token_relation_graph_query_dune():
    global excutionid , dune_api
    
    
    file_name = f"one_token_relation_graph_{excutionid}.csv"
    file_path = baseclass.dune_excution_path /file_name
    if file_path.exists():
        print(f"file_name= {file_name} already exists, skip download")
        return
    
    url = f"https://api.dune.com/api/v1/execution/{excutionid}/results/csv"
    headers = {"X-DUNE-API-KEY": dune_api}
    response = requests.request("GET", url, headers=headers)
    response_text = response.text
    print(response_text)

    # print(response.text)
    with open(file_path, "w", encoding="utf-8") as file:
        # 将 response.text 写入文件
        file.write(response_text)


    return





dune_api = 'W7zTOtVucO0CepixObF7MgGGTzqUYqbM'
#  arr_duneapi=['W7zTOtVucO0CepixObF7MgGGTzqUYqbM']

excutionid ='01JBXRQNBWHRQ0RT66W4AC1QFE'

# Query	one_token_relation_graph
# Execution Id	01JBXRQNBWHRQ0RT66W4AC1QFE
# Execution time
# 6.4670000076293945 seconds
# Wall time
# 9.043000221252441 seconds
# Analysis time
# 2.575000047683716 seconds
# CPU time
# 440.3890075683594 seconds
# Queued time
# 0 seconds
# Physical input	2074654689 rows (86.1 GB)
# Output	214 rows (44.7 KB)
# Peak task total memory	837.2 MB

get_one_token_relation_graph_query_dune()


print(f"{'{:<6}'.format('END')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")

