Friday, November 22, 2024

How can I get the date of the final transaction from the blockchain.information API?

import requests
import time

def check_address_last_transaction_dates(filename):
with open(filename, ‘r’) as file:
address_list = [line.strip() for line in file]

for deal with in address_list:
    url = f"https://blockchain.information/deal with/{deal with}?format=json"
    response = requests.get(url)
    
    if response.status_code == 200:
        knowledge = response.json()

        if "txs" in knowledge:
            # Discover the latest transaction within the listing of transactions
            transactions = knowledge["txs"]
            if transactions:
                most_recent_tx = max(transactions, key=lambda x: x["time"])
                last_tx_date = most_recent_tx["time"]
                last_tx_date_formatted = format_timestamp_to_month_year(last_tx_date)
                print(f"Handle: {deal with}, Final Transaction Date: {last_tx_date_formatted}n")
            else:
                print(f"Handle: {deal with}, No final transaction knowledge availablen")
        else:
            print(f"Handle: {deal with}, No transaction knowledge availablen")
    else:
        print(f"Handle: {deal with}, Error fetching datan")
    
    # Introduce a 1-second delay between checking addresses
    time.sleep(1)

def format_timestamp_to_month_year(timestamp):
# Convert UNIX timestamp to month/yr format
from datetime import datetime
date = datetime.utcfromtimestamp(timestamp)
return date.strftime(“%B %Y”)

filename = “btc500.txt”

check_address_last_transaction_dates(filename)

with this code you possibly can test final transaction date/yr solely no different data…..exchange your btc deal with listing file with btc500.txt

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles