

import requests


 
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---------------")
 
url_0 = "https://solana-mainnet.g.alchemy.com/v2/WLI0ohbUlvbsJVmoIvB1wTSwUA8qP5qS"


url_1 = ("https://solana-mainnet.g.alchemy.com/v2/ck1dtOx8tHkjAH2PX2FwTGN2T2gDaGtV")
url_2 = "https://solana-mainnet.g.alchemy.com/v2/pxF-cEkEE1JxzxgotGyww5ra5w1IvAkJ"


getBalance_payload = {
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getBalance",
    "params": []
}
headers = {
    "accept": "application/json",
    "content-type": "application/json"
}

df =  pd.read_excel( baseclass.dalao_merge_defined_path / f"ori_merge_defined.xlsx", dtype=object)
df= df.astype({
    "eth":float
})
df = df.drop_duplicates(subset=["dalaoaddress"])
df =df.reset_index(drop=True)

df_not_getbalance =df[ df["eth"]==-1]
df_not_getbalance_len = len(df_not_getbalance)
arr_str_dalaoaddress = df_not_getbalance['dalaoaddress'].tolist()
 
    
for idx , str_dalaoaddress in  enumerate(arr_str_dalaoaddress):
    # print(f"str_dalaoaddress={str_dalaoaddress}")
    getBalance_payload["params"] = [str_dalaoaddress]
    
    response = requests.post(url_1, json=getBalance_payload, headers=headers)
    if response.status_code != 200:
        continue
        
    response_data = response.json()
    eth_value = response_data["result"]["value"] / (10**9)
    df.loc[ df["dalaoaddress"] ==str_dalaoaddress , "eth"] = eth_value
    print(f"str_dalaoaddress={str_dalaoaddress} eth_value={eth_value}")
    if idx%15==0:
        df.to_excel( baseclass.dalao_merge_defined_path / f"ori_merge_defined.xlsx", index=False)
    if idx%30==0:
        print(f"current process {idx}/{df_not_getbalance_len }")
   
 
 
df.to_excel( baseclass.dalao_merge_defined_path / f"ori_merge_defined.xlsx", index=False)

 

