I am trying to create a python script to read a json report file (that contains status of tasks getting executed). so, when i run my script, i need to show the current status parsing the json report file and updating it in real time. i want it to run something like a linux 'top' command where the details get updated in real time until you choose to exit.
here is the code that i tried to come up with:
import json
import time
while True:
with open('/tmp/install-report.json') as json_data:
d = json.load(json_data)
for key, value in d.iteritems():
print key, value
time.sleep(1)
so when i run it, the output keeps showing in a loop while messing up the console.
however, i need to show only the snapshot of the parsed json file. if there is any update in the json file, the output should show the updated information instead of running into a loop of output on the console.
please let me know how i can correct the above script to achieve what i want.