I have looked around at some of the questions already asked but none of them seem to fit my situation. So I have a very basic program the shows me the current value of bitcoin:
import requests
import os
import sys
import time
while True:
main_api = ('https://api.coindesk.com/v1/bpi/currentprice.json')
json_data = requests.get(main_api).json()
json_updated = json_data['time']['updated']
json_value = json_data['bpi']['USD']['rate']
time.sleep(1)
print('\n' 'Last Updated: ' + json_updated)
print('\n' "Bitcoin price: " + json_value + " USD")
and it works well for the most part. But there is a small problem, every time the code executes itself (every second) it will create more text in the terminal displaying the currency and the last time it was updated. But It will not remove the previous text which makes it look ugly and a bit confusing so I aim to make it look like, in the terminal, that there is only once instance of the text that updates itself, giving a much more cleaner look.
I have seen some solutions like:
for x in range(10):
print(x, end='\r')
print()
from How to overwrite the previous print to stdout in python?
and
import time
for x in range (0,5):
b = "Loading" + "." * x
print (b, end="\r")
time.sleep(1)
from Remove and Replace Printed items
But I honestly have no idea how or IF I can incorporate those solutions into my own code since my program is much more different from the ones used in the solutions or I am just I noob, probably the latter lol.
Thanks.