
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 = "https://solana-mainnet.g.alchemy.com/v2/pxF-cEkEE1JxzxgotGyww5ra5w1IvAkJ"
 
getBalance_payload = {
  
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getBalance",
    "params": [  ]
}
 

def filter_onhand_dalao():

    df = pd.read_excel(baseclass.dalao_merge_path /
                       "un_onhand_dalao.xlsx", dtype=object)

    df["Maker_isNormal"] = df["Maker_isNormal"].astype(int)
    
    filter_mask_not_Maker_isNormal = df["Maker_isNormal"]==0
    arr_not_Maker_isNormal = df[filter_mask_not_Maker_isNormal]["Maker"].drop_duplicates().tolist()
    arr_drop_Maker=[]
    while len(arr_not_Maker_isNormal)>0:
        if len(arr_not_Maker_isNormal)%10==0:
            print(f"remainder len = {len(arr_not_Maker_isNormal)}")
        
        str_maker =arr_not_Maker_isNormal[0]
        getBalance_payload["params"] = [str_maker]
        
        req_response = requests.post(url, json=getBalance_payload, headers=baseclass.headers,timeout=5)
        if req_response.status_code != 200:
            print(" req_response.status_code=", req_response.status_code)
            time.sleep(2)
            continue
        arr_not_Maker_isNormal.pop(0)
        response = json.loads(
            req_response.text)
        dalao_balance = int(response["result"]['value'])/10**9
        
        if dalao_balance<0.3:
            arr_drop_Maker.append(str_maker)
        if len(arr_drop_Maker)%10==0:
            df = df[~df["Maker"].isin(arr_drop_Maker)].reset_index(drop=True)
            df.to_excel(baseclass.dalao_merge_path /
              "un_onhand_dalao.xlsx", index=False)
 
    # https://dexscreener.com/solana/9s9sgqskfyzbygm45qblje4rt6calfa2dbhjrevlszrc?maker=47TwqZwwMGHc9CkJJxvVgFNGLDqBuSPy95KwUSTcLSti
 
    df.to_excel(baseclass.dalao_merge_path /
              "un_onhand_dalao.xlsx", index=False)

    return


filter_onhand_dalao()


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