spl_csv_search.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Program to search through Solscan
  2. # TODO:
  3. # 1) Program donwloading history of solscan into csv according given parameters
  4. # 2) Program exploring the alle, txhash, amont, time etc
  5. # 3) API remote controllng program
  6. import csv
  7. from datetime import datetime
  8. from tabulate import tabulate
  9. def get_info():
  10. """Functiong extractiong info from the downloaded csv file"""
  11. filename = 'data/export_transfer_undefined_1654954858887.csv'
  12. with open(filename) as f:
  13. reader = csv.reader(f)
  14. header_row = next(reader)
  15. # This passes the next line (1st = header)
  16. # for index, column_header in enumerate(header_row):
  17. # print(index, column_header)
  18. times, txhashes, amounts, source_owners, dest_owners = [], [], [], [], [],
  19. for row in reader:
  20. time_index = header_row.index('BlockTime')
  21. txhash_index = header_row.index('TxHash')
  22. amount_index = header_row.index('Amount')
  23. source_own_index = header_row.index('Source Owner Account')
  24. dest_own_index = header_row.index('Dest Owner Account')
  25. try:
  26. txhash = str(row[txhash_index])
  27. amount = float(row[amount_index])
  28. src_own = str(row[source_own_index])
  29. dst_own = str(row[dest_own_index])
  30. date_time = f"{row[time_index]}"
  31. # hover_date_time = \
  32. # datetime.strptime(date_time, '%Y-%m-%d, %H%M')
  33. except IndexError:
  34. print(f"Missing data")
  35. else:
  36. times.append(date_time)
  37. txhashes.append(txhash)
  38. amounts.append(amount)
  39. source_owners.append(src_own)
  40. dest_owners.append(dst_own)
  41. return times, txhashes, amounts, source_owners, dest_owners
  42. def display_csv_txs_usdt(min=1000000,max=10000000):
  43. """Prints all tx's within the range of entered amount"""
  44. headers = _headers_txs_usdt(min,max)
  45. times, txhashes, amounts, source_owners, dest_owners = get_info()
  46. table = [
  47. headers[0],
  48. headers[1],
  49. headers[2]
  50. ]
  51. for index,amount in enumerate(amounts):
  52. usdt = amount/1000000
  53. i = index
  54. txhash = txhashes[i]
  55. src_own = source_owners[i]
  56. dst_own = dest_owners[i]
  57. time = times[i]
  58. if usdt > min and usdt < max:
  59. item =(f"{time} - ",
  60. f"{txhash} - ",
  61. f"{src_own} - ",
  62. f"{dst_own} - ",
  63. f"{usdt}"
  64. )
  65. table.append(item)
  66. print(tabulate(table))
  67. def _headers_txs_usdt(min,max):
  68. """Support function to print the header for tx's in usdt"""
  69. header_0 = (f"\nTRANSACTIONS BETWEEN {min} and {max} USDT",)
  70. header_1 = ("=======================================",)
  71. header_2 = (
  72. "TIME",
  73. "TXHASH",
  74. "SOURCE OWNER",
  75. "DESTINATION OWNER",
  76. "AMOUNT (USDT)"
  77. )
  78. headers = [header_0,header_1,header_2]
  79. return headers
  80. display_csv_txs_usdt(5000,5550)