005_dalaotransfer_dropduplicate_solanafm.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import json
  2. import shutil
  3. import urllib.parse
  4. from base_class import BaseVariableFunction
  5. from base_class import *
  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. baseclass = BaseVariableFunction(__file__)
  12. print('\n'*5)
  13. print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")
  14. utc_timeto = int(time.time())
  15. utc_timefrom = int(utc_timeto - 17*24*3600)
  16. def one_dalaotransfer_dropduplicate(str_dalao_address, success_address_list):
  17. try:
  18. # for str_dalao_address in arr_str_dalaoaddress:
  19. # print(f"enter str_dalao_address= {str_dalao_address}")
  20. dalao_file = baseclass.dalao_transfer_solanafm_path / \
  21. f"{str_dalao_address}.json"
  22. if not dalao_file.exists():
  23. return
  24. new_arr_obj_dalao_transaction = []
  25. new_arr_txhash = []
  26. try:
  27. with dalao_file.open(mode='r', encoding='utf-8') as f:
  28. arr_obj_dalao_transaction = json.load(f)
  29. except Exception as e:
  30. print(f"read_json_error str_dalao_address={str_dalao_address}")
  31. raise
  32. for obj_dalao_transaction in arr_obj_dalao_transaction:
  33. txhash = obj_dalao_transaction["transactionHash"]
  34. timestamp = obj_dalao_transaction["data"][0]["timestamp"]
  35. if txhash in new_arr_txhash:
  36. continue
  37. if timestamp <= utc_timefrom :
  38. continue
  39. new_arr_txhash.append(txhash)
  40. new_arr_obj_dalao_transaction.append(obj_dalao_transaction)
  41. with dalao_file.open(mode='w', encoding='utf-8') as f:
  42. json.dump(new_arr_obj_dalao_transaction, f)
  43. success_address_list.remove(str_dalao_address)
  44. print(
  45. f"str_dalao_address= {str_dalao_address} prelen= {len(arr_obj_dalao_transaction)} aftlen= {len(new_arr_obj_dalao_transaction)} remainder= {len(success_address_list)} \n", end='')
  46. except Exception as e:
  47. print(f"error_str_dalao_address={str_dalao_address}")
  48. raise
  49. def mul_dalaotransfer_dropduplicate():
  50. success_address_list = arr_str_dalaoaddress.copy()
  51. for idx in range(0, len(arr_str_dalaoaddress), batchSize):
  52. thread_list = []
  53. for cur_idx in range(idx, min(idx+batchSize, len(arr_str_dalaoaddress))):
  54. thread = threading.Thread(
  55. target=one_dalaotransfer_dropduplicate,
  56. args=(arr_str_dalaoaddress[cur_idx],
  57. success_address_list)
  58. )
  59. thread_list.append(thread)
  60. for thread in thread_list:
  61. thread.start()
  62. for thread in thread_list:
  63. thread.join()
  64. time.sleep(1)
  65. return
  66. arr_str_dalaoaddress = []
  67. df = pd.read_csv(baseclass.dalao_merge_path /
  68. "filter_dalao.csv", dtype=object)
  69. arr_str_dalaoaddress = df["dalaoAddress"].tolist()
  70. print('arr_str_dalaoaddress', len(arr_str_dalaoaddress))
  71. batchSize = 170
  72. mul_dalaotransfer_dropduplicate()
  73. print(f"{'{:<6}'.format('END')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")