I have a question about the time.sleep
command in a if/else
loop. I make an api request for different places with the latitude and longitude. All in all, I need the request for 5 years. I use two for
loops over the latitude and longitude and over the requested five years. The problem is that I can only send 6 requests per minute. Because of that, I use the time.sleep
command as follow:
for lat, lon in zip(lats, lons):
for year in years:
args = {
'interpolate': False,
'lat': lat,
'lon': lon,
'date_from': year + '-01-01',
'date_to': year + '-12-31',
'capacity': 500,
'height': 44,
'turbine': 'Enercon E40 500',
'format': 'json',
'metadata': False,
'raw': True,
}
r = s.get(url, params=args)
data = pd.read_json(r.text, orient='index')
df = df.append(data)
time.sleep(61)
The function works good and the time.sleep
command too! But in this form, the function waits 61 seconds after the last passing. I wanna make this a litte bit "smoother" with an if/else
loop in that way, if the loop uses the last latitude/longitude, the time.sleep
command can be ignored. The years are a normal list and the latitude/longitude are in a seperate excel table. Has someone a idea, how I can write this? The ways I tried it doesn't work and I need some new inspiration...Thank you!