【问题标题】:Darksky Loop through one year of daily data - Datetime ErrorDarksky 循环遍历一年的每日数据 - 日期时间错误
【发布时间】:2020-02-18 21:49:33
【问题描述】:

我尝试使用 forecastiopy 循环浏览 2019 年的每日天气数据,但错误一直显示。不确定是什么问题。

import pandas as pd 
import requests
import json 
from forecastiopy import *
from datetime import date, timedelta, datetime
import datetime

key = 'xxxxx'

city = [40.730610, -73.935242]
start = datetime.datetime(2019, 1, 1)


for day in range(1,365):
    fio = ForecastIO.ForecastIO(key,
                        units=ForecastIO.ForecastIO.UNITS_SI,
                        lang=ForecastIO.ForecastIO.LANG_ENGLISH,
                        latitude=city[0], 
                        longitude=city[1],
                        time=start+datetime.timedelta(day))
    daily = FIODaily.FIODaily(fio)
    print ('Max Temperature', daily.get_day(day)['temperatureMax'])
    print ('Min Temperature:', daily.get_day(day)['temperatureMin'])
    print ('Precipitation Pobability:', daily.get_day(day)['precipProbability'])
    print ('Precipitation Intensity', daily.get_day(day)['precipIntensity'])

显示的错误如下。

【问题讨论】:

    标签: python darksky


    【解决方案1】:
    ForecastIO.ForecastIO(key,
        ...,
        time=start+datetime.timedelta(day))
    

    这里,time 参数应该是一个直接映射到Dark Sky API 的字符串:

    时间

    可以是 UNIX 时间(即从午夜开始的秒数) 格林威治标准时间 1970 年 1 月 1 日)或格式如下的字符串: [YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone]。 [...]

    因此,您可以使用isoformat() 格式化datetime 对象

    ForecastIO.ForecastIO(key,
        ...,
        time=(start+datetime.timedelta(day)).isoformat())
    

    【讨论】:

      猜你喜欢
      • 2018-09-03
      • 2021-05-25
      • 1970-01-01
      • 2011-01-05
      • 2018-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多