-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathGet_First_Transaction.py
52 lines (41 loc) · 1.91 KB
/
Get_First_Transaction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
from datetime import datetime
def get_first_transaction(wallet_address):
# Construct the URL for getting transaction history for the specified address
url = f'https://btcscan.org/api/address/{wallet_address}/txs/chain'
# Make the GET request to the API
response = requests.get(url)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the JSON response
transactions = response.json()
# Check if there are any transactions
if transactions:
# Retrieve information about the first transaction
first_transaction = transactions[0]
return first_transaction
else:
return None
else:
# Print an error message if the request was not successful
print(f"Error: {response.status_code}, {response.text}")
return None
def get_date_from_block_time(block_time):
# Convert block time (Unix timestamp) to a human-readable date
return datetime.utcfromtimestamp(block_time).strftime('%Y-%m-%d %H:%M:%S UTC')
def process_addresses(input_file, output_file):
with open(input_file, 'r') as f:
addresses = f.read().splitlines()
for wallet_address in addresses:
first_transaction_info = get_first_transaction(wallet_address)
# Write the information to the output file in real-time
with open(output_file, 'a') as output:
output.write(f"{wallet_address}\n")
if first_transaction_info:
output.write(f"{get_date_from_block_time(first_transaction_info['status']['block_time'])}\n\n")
else:
output.write("No transactions found for the specified wallet.\n")
# Flush the output buffer to write to the file in real-time
output.flush()
if __name__ == "__main__":
process_addresses('List_of_wallets.txt', 'Output_BTC_TX_Date.txt')