Darksky 循环一年的日常数据 - 日期时间错误
Darksky Loop through one year of daily data - Datetime Error
我尝试使用 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'])
显示的错误如下。
ForecastIO.ForecastIO(key,
...,
time=start+datetime.timedelta(day))
这里,time
参数应该是一个直接映射到Dark Sky API:
的字符串
time
Either be a UNIX time (that is, seconds since midnight
GMT on 1 Jan 1970) or a string formatted as follows:
[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone]
. [...]
因此,您可以使用 isoformat()
格式化 datetime
对象
ForecastIO.ForecastIO(key,
...,
time=(start+datetime.timedelta(day)).isoformat())
我尝试使用 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'])
显示的错误如下。
ForecastIO.ForecastIO(key, ..., time=start+datetime.timedelta(day))
这里,time
参数应该是一个直接映射到Dark Sky API:
time
Either be a UNIX time (that is, seconds since midnight GMT on 1 Jan 1970) or a string formatted as follows:
[YYYY]-[MM]-[DD]T[HH]:[MM]:[SS][timezone]
. [...]
因此,您可以使用 isoformat()
datetime
对象
ForecastIO.ForecastIO(key,
...,
time=(start+datetime.timedelta(day)).isoformat())