2001_getbalance_eth.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import requests
  2. from base_class import BaseVariableFunction
  3. from base_class import *
  4. baseclass = BaseVariableFunction(__file__)
  5. old_print = print
  6. def timestamped_print(*args, **kwargs):
  7. old_print(datetime.datetime.utcnow().replace(
  8. microsecond=0), *args, **kwargs)
  9. print = timestamped_print
  10. print('\n'*5)
  11. print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")
  12. url = "https://solana-mainnet.g.alchemy.com/v2/WLI0ohbUlvbsJVmoIvB1wTSwUA8qP5qS"
  13. getBalance_payload = {
  14. "id": 1,
  15. "jsonrpc": "2.0",
  16. "method": "getBalance",
  17. "params": []
  18. }
  19. headers = {
  20. "accept": "application/json",
  21. "content-type": "application/json"
  22. }
  23. df = pd.read_excel( baseclass.dalao_merge_defined_path / f"ori_merge_defined.xlsx", dtype=object)
  24. df= df.astype({
  25. "eth":int
  26. })
  27. df = df.drop_duplicates(subset=["dalaoaddress"])
  28. df =df.reset_index(drop=True)
  29. df_not_getbalance =df[ df["eth"]==-1]
  30. arr_str_dalaoaddress = df_not_getbalance['dalaoaddress'].tolist()
  31. for idx , str_dalaoaddress in enumerate(arr_str_dalaoaddress):
  32. print(f"str_dalaoaddress={str_dalaoaddress}")
  33. getBalance_payload["params"] = [str_dalaoaddress]
  34. response = requests.post(url, json=getBalance_payload, headers=headers)
  35. if response.status_code != 200:
  36. continue
  37. response_data = response.json()
  38. eth_value = response_data["result"]["value"] / (10**9)
  39. df.loc[ df["dalaoaddress"] ==str_dalaoaddress , "eth"] = eth_value
  40. print(f"str_dalaoaddress={str_dalaoaddress} eth_value={eth_value}")
  41. if idx%5==0:
  42. df.to_excel( baseclass.dalao_merge_defined_path / f"ori_merge_defined.xlsx", index=False)
  43. df.to_excel( baseclass.dalao_merge_defined_path / f"ori_merge_defined.xlsx", index=False)