【发布时间】:2021-11-12 11:55:45
【问题描述】:
每当我运行代码时,此代码都会打印它从 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")
【问题讨论】:
-
以某种方式保留最后一个结果(pickle、文件、xml、...)在 scripstart 上加载它,将其与您当前的值进行比较。关于在这里存储信息的大量问题 - 搜索 python + pickle。如果您这样做,打印或不打印不再是问题。
标签: python api logging blockchain solidity