繁体   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