简体   繁体   中英

I want my code to print only if the result is different from previous result and not the same thing again

This code prints the most recent result that it fetches from api_url whenever I run the code, but I want it to check if result is same as last then do not print it.

Note: This is my first time asking a question here so please forgive, If I made any mistake in the question.

 api_url= "https://api.bscscan.com/api? module=account&action=tokentx&contractaddress=smartcontract&address=" + person1["address"] + \
    "&startblock=10290674&endblock=999999999&page=1&offset=1&sort=desc&apikey=APIKEY"

 response = requests.get(api_url)
 address_content = response.json()
 result = address_content.get("result")  

 for n, transaction in enumerate(result):
    block = transaction.get("blockNumber")
    hash = transaction.get("hash")
    tx_from = transaction.get("from")
    tx_to = transaction.get("to")
    value = transaction.get("value")
    confirmations = transaction.get("confirmations")

    coin_value = Decimal(value)/1000000000000000000

    coin_value = int(value)/1000000000
    print("COIN", coin_value)
    print("\n")
    
    if tx_to in (tx_sell, tx_sell2):
        print("sell")
    elif tx_from in (tx_sell, tx_sell2):
        print("buy")

store the result in a filelike:

myfile = open(“result.txt”,’w’)

myfile.write(str(result))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM