微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使用 Wea​​therbit API 从 Python 中解析 JSON 数据

如何解决如何使用 Wea​​therbit API 从 Python 中解析 JSON 数据

enter image description here我一直试图弄清楚如何解析从我使用的 API 中获取的数据,以便我可以将其转换为 MysqL 并将其添加到表中,但我没有真的知道该怎么做,因为我对 python 还很陌生。

我的代码是这样的:

from weatherbit.api import Api
api_key = "API key"
lat = 39.7029
lon = 75.1118

api = Api(api_key)

    # Set the granularity of the API - Options: ['daily','hourly','3hourly']
    # Will only affect forecast requests.
api.set_granularity('daily')

    # Or City,state,and country:
forecast = api.get_forecast(city="Glassboro",state="New Jersey",country="US")

    # To get a daily forecast of temperature,and precipitation:
print (forecast.get_series(['temp','precip']))

    # Get daily history by lat/lon:
api.set_granularity('daily')
history = api.get_history(lat=lat,lon=lon,start_date='2021-03-04',end_date='2021-03-05')

    # To get a daily time series of temperature,precipitation,and rh:
print (history.get_series(['precip','temp','rh']))

...
 
input ('')

我收到了它的响应,但它的可读性不是很好,不能用于添加MysqL 中的表中,有什么办法可以做到这一点?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。