'how to refresh this api so it's get updated every 5 seconds
eth_api = "https://api.coinbase.com/v2/exchange-rates?currency=ETH"
headers = {"Accept": "application/json"}
r = requests.request("GET", eth_api, headers=headers)
data2 = r.json()
eth_price = data2['data']['rates']['USD']
print (eth_price)
I am still new to this, tried other ways but they are not effective, i want to reuse this in commands
Solution 1:[1]
By updating do you mean to run this block of code every 5 seconds. If you are trying to do that then you have to put the block of code in a while loop and put time.sleep(5) to run the loop every 5 seconds. NOTE ~ You can't close the running process or the loop will stop so as your script.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sagar Newpane |
