021_02_get_dalaotxhash_solscan.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import random
  2. from base_class import BaseVariableFunction
  3. from base_class import *
  4. baseclass = BaseVariableFunction(__file__)
  5. baseclass.makedirpath(baseclass.dalao_tran_txhash_path)
  6. old_print = print
  7. def timestamped_print(*args, **kwargs):
  8. old_print(datetime.datetime.utcnow().replace(
  9. microsecond=0), *args, **kwargs)
  10. print = timestamped_print
  11. print('\n'*5)
  12. print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")
  13. # Python中windows路径的3种写法
  14. # 可以是以下这样写:
  15. utc_timeto = int(time.time())
  16. utc_timefrom = int(utc_timeto - 17*24*3600)
  17. df = pd.read_excel(baseclass.dalao_total_ana_fm_path /
  18. "anaing_dalao.xlsx", dtype=object)
  19. arr_str_dalaoAddress = df['add'].tolist()
  20. arr_str_dalaoAddress.append(baseclass.mywalletaddress)
  21. print('arr_str_dalaoAddress', len(arr_str_dalaoAddress))
  22. for str_dalaoaddress in arr_str_dalaoAddress:
  23. print("str_dalaoaddress=", str_dalaoaddress)
  24. if not (baseclass.dalao_ori_tran_txhash_solscan_path/f"ori_txhash_{str_dalaoaddress}.csv").exists():
  25. continue
  26. obj_txhash_timestamp = {
  27. "txhash": [],
  28. "timestamp": [],
  29. "TokenAccount":[],
  30. }
  31. with open(baseclass.dalao_ori_tran_txhash_solscan_path /
  32. f"ori_txhash_{str_dalaoaddress}.csv", mode="r", encoding="utf-8") as f:
  33. arr_line = f.read().strip().split("\n")
  34. arr_line.pop(0)
  35. arr_line.pop()
  36. line =None
  37. try:
  38. for line in arr_line:
  39. if line.strip() == '':
  40. continue
  41. arr_split_line = line.split(",")
  42. if " " in arr_split_line[0] :
  43. arr_split_line[0]= arr_split_line[0].strip()[1:]
  44. str_TokenAccount = arr_split_line[4].strip()
  45. if str_TokenAccount== str_dalaoaddress:
  46. continue
  47. obj_txhash_timestamp["txhash"].append(arr_split_line[0])
  48. obj_txhash_timestamp["timestamp"].append(arr_split_line[1])
  49. obj_txhash_timestamp["TokenAccount"].append( str_TokenAccount)
  50. except Exception as e:
  51. print("error line=",line)
  52. raise
  53. new_df = pd.DataFrame(obj_txhash_timestamp)
  54. df = None
  55. if (baseclass.dalao_tran_txhash_path/f"txhash_{str_dalaoaddress}.csv").exists():
  56. df = pd.read_csv(baseclass.dalao_tran_txhash_path /
  57. f"txhash_{str_dalaoaddress}.csv", dtype=object)
  58. df = pd.concat([new_df, df])
  59. df =df.replace('',np.nan)
  60. df =df.dropna(axis=0,how='any')
  61. df["timestamp"] = df["timestamp"].astype(int)
  62. df = df[df["timestamp"] >= utc_timefrom]
  63. df = df.drop_duplicates(subset=["txhash"]).reset_index(drop=True)
  64. df = df.sort_values(by=["timestamp"], ascending=[False])
  65. df.to_csv(baseclass.dalao_tran_txhash_path /
  66. f"txhash_{str_dalaoaddress}.csv", index=False)
  67. print(f"{'{:<6}'.format('END')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")