每分钟Weather Undground API调用限制 [英] Weather Undground API call limit per minute

查看:141
本文介绍了每分钟Weather Undground API调用限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将我的API请求限制为每分钟10次调用,如何修改for循环来完成此操作?

I have to limit my API request to 10 calls per minute, how can I modify the for loops to accomplish this?

我试图在for observation循环中添加time.sleep(8),但没有任何运气...有什么想法吗?

I am trying to add in time.sleep(8) in the for observation loop without any luck... Any ideas?

import arrow # learn more: https://python.org/pypi/arrow
from WunderWeather import weather # learn more: https://python.org/pypi/WunderWeather
import time

api_key = ''
extractor = weather.Extract(api_key)
zip = '53711'

# get 20170101 00:00
begin_date = arrow.get("2017","YYYY")
# get 20171231 23:00
end_date = arrow.get("2018","YYYY").shift(hours=-1)
for date in arrow.Arrow.range('hour',begin_date,end_date):
  # get date object for feature
  # http://wunderweather.readthedocs.io/en/latest/WunderWeather.html#WunderWeather.weather.Extract.date
  date_weather = extractor.date(zip,date.format('YYYYMMDD'))

  # use shortcut to get observations and data
  # http://wunderweather.readthedocs.io/en/latest/WunderWeather.html#WunderWeather.date.Observation
  for observation in date_weather.observations:
    time.sleep(8)
    print("Date:",observation.date_pretty)
    print("Temp:",observation.temp_f)

推荐答案

根据您想要数据的实时程度或可以承受一天的落后时间,您可以获得过去某个日期的所有观测值,而该日期将是API调用,以检索一天的数据(或者可以是当天观测值的一天结束摘要).

Depending on how realtime you want your data or you can afford to be a day behind, you could get all observations for a date in the past which would be one API call to retrieve data for a day(or it could be an end of day summary for the current day's observations).

或者,如果您尝试每隔约x分钟获取当前天气(低于限制) 我会在计时器上使用某种形式的循环(或者可能是扭曲的,这似乎抽象了循环"),但调用以下内容之一(取决于您要查找的内容).您当前的代码正在查找过去的日期,但这些其他端点是当天的.

Alternatively, if you're trying to get the current weather every x minutes or so (under the limit) I'd use some sort of loop with a timer (or possibly twisted which seems to abstract the "loop") but make a call to one of the following (depending on what you're looking for). Your current code is looking for dates in the past but these other endpoints are for the current day.

您不希望计时器进入观察循环,因为如上所述,可能没有计时器.

You don't want the timer in the observations loop since, as mentioned above, there might be none.

http://wunderweather.readthedocs.io/en/latest/WunderWeather.html#WunderWeather.weather.Extract.hourly_daycast

http://wunderweather.readthedocs.io/en/latest/WunderWeather.html#WunderWeather.weather.Extract.today_now

可以类似于以下示例进行调用 http://wunderweather.readthedocs.io/en/latest/index. html#additional-examples

which can be called similar to the following examples http://wunderweather.readthedocs.io/en/latest/index.html#additional-examples

这篇关于每分钟Weather Undground API调用限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆