簡體   English   中英

我希望我的代碼僅在結果與之前的結果不同且不再相同時才打印

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

每當我運行代碼時,此代碼都會打印它從 api_url 獲取的最新結果,但我希望它檢查結果是否與上次相同,然后不打印它。

注意:這是我第一次在這里提問,所以如果我在問題中犯了任何錯誤,請原諒。

 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")

將結果存儲在一個文件中:

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

myfile.write(str(result))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM