004_02_get_dalaotxhash_solscan.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_csv(baseclass.dalao_merge_path /
  18. "filter_dalao.csv", dtype=object)
  19. arr_str_dalaoAddress = df['dalaoAddress'].tolist()
  20. print('arr_str_dalaoAddress', len(arr_str_dalaoAddress))
  21. for str_dalaoaddress in arr_str_dalaoAddress:
  22. print("str_dalaoaddress=", str_dalaoaddress)
  23. if not (baseclass.dalao_ori_tran_txhash_solscan_path/f"ori_txhash_{str_dalaoaddress}.csv").exists():
  24. continue
  25. obj_txhash_timestamp = {
  26. "txhash": [],
  27. "timestamp": [],
  28. }
  29. with open(baseclass.dalao_ori_tran_txhash_solscan_path /
  30. f"ori_txhash_{str_dalaoaddress}.csv", mode="r", encoding="utf-8") as f:
  31. arr_line = f.read().strip().split("\n")
  32. arr_line.pop(0)
  33. arr_line.pop()
  34. line =None
  35. try:
  36. for line in arr_line:
  37. if line.strip() == '':
  38. continue
  39. arr_split_line = line.split(",")
  40. if " " in arr_split_line[0] :
  41. arr_split_line[0]= arr_split_line[0].strip()[1:]
  42. obj_txhash_timestamp["txhash"].append(arr_split_line[0])
  43. obj_txhash_timestamp["timestamp"].append(arr_split_line[1])
  44. except Exception as e:
  45. print("error line=",line)
  46. raise
  47. new_df = pd.DataFrame(obj_txhash_timestamp)
  48. df = None
  49. if (baseclass.dalao_tran_txhash_path/f"txhash_{str_dalaoaddress}.csv").exists():
  50. df = pd.read_csv(baseclass.dalao_tran_txhash_path /
  51. f"txhash_{str_dalaoaddress}.csv", dtype=object)
  52. df = pd.concat([new_df, df])
  53. df =df.replace('',np.nan)
  54. df =df.dropna(axis=0,how='any')
  55. df["timestamp"] = df["timestamp"].astype(int)
  56. df = df[df["timestamp"] >= utc_timefrom]
  57. df = df.drop_duplicates().reset_index(drop=True)
  58. df = df.sort_values(by=["timestamp"], ascending=[False])
  59. df.to_csv(baseclass.dalao_tran_txhash_path /
  60. f"txhash_{str_dalaoaddress}.csv", index=False)
  61. print(f"{'{:<6}'.format('END')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")