I need to get data from an API every 30 seconds and compare them with the previous values. One of the ways is using a "While True" loop.
Here is a brief explanation of my code :
import requests
import json
import datetime
List1 = []
List2 = []
while True :
Url = ' the URL of the API'
request1 = requests.request("GET", URL)
#get the data and append them to List1
List1.append(data1)
time.sleep(30)
request2 = requests.request("GET", URL)
#get the data and append them to List2
List2.append(data2)
#eventually, some logics using List1 and List2:
blah blah blah...............
When I use the above code, I get some repetitive outputs every random time. However, if we delete "while true", the code will run one time and we will not have repetitive output.
(Let me explain more: for example, if a code runs for 5 times and the names of the outputs are 1,2,3,4 and 5; when I run the above code(with while true) I will have these outputs: 1,2,1,4,2)
Why is this happening??
question from:
https://stackoverflow.com/questions/65861060/repetitive-outputs-during-getting-an-api-data-every-30-seconds-using-a-while-tru 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…