Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何计算天气api中的值_Python_Openweathermap_Weather Api - Fatal编程技术网

Python 如何计算天气api中的值

Python 如何计算天气api中的值,python,openweathermap,weather-api,Python,Openweathermap,Weather Api,如何计算天气api的响应,如: a = x["wind"]["speed"] returns like 3.09 b = x["wind"]["deg"] return 36 c = x["visibility"] returns 2200 d = x["main"]["sea_level"] returns 1004 e = x["main&q

如何计算天气api的响应,如:

a = x["wind"]["speed"] returns like 3.09 
b = x["wind"]["deg"] return 36
c = x["visibility"] returns 2200
d = x["main"]["sea_level"] returns 1004
e = x["main"]["grnd_level"] returns 979
f = x["sys"]["sunrise"] returns like 1621468669
g = x["sys"]["sunset"] return like 1621517866

如何计算
f
g
的时间;
a
的速度;
b
的方向;
c
的可见性;
d
e
的级别(米)

如果我没有弄错,这些整数值就是UNIX时间戳。要获取相应的日期时间,请执行以下操作:

from datetime import datetime

dateobjf = datetime.fromtimestamp(f+x["timezone"])
dateobjg = datetime.fromtimestamp(g+x["timezone"])
编辑:
x[“时区”]
添加到某些给定时区的返回时间。 编辑2:用于打印GMT偏移的代码:

hrs = abs(x["timezone"])//3600
mins = abs(x["timezone"])//60-hrs*60
if x["timezone"]>0:
    tzinfo = f"GMT +{hrs}:{mins:02d}"
elif x["timezone"]==0:
    tzinfo = "GMT 0:00"
else:
    tzinfo = f"GMT -{hrs}:{mins:02d}"
print(tzinfo)

现在还不清楚你想要实现什么?你能提供这个API文档的链接吗?到目前为止你有什么?你拿到结果了吗?它是什么样子的?我的意思是它返回如图所示的值,但就像在sunrise案例中,我如何使用返回的值计算时间我将这些数字识别为UNIX时间戳,我为此编写了一个解决方案。以及如何计算
a
的风速,方向如
b
的南、北,
c
的可见性以及
d
e
的高度(以米为单位)您必须阅读API文档,我不知道
a
的单位是什么,可能是m/s,但是
b
是以度为单位的角度,
c
看起来像是以米为单位的,
d
e
。最后,其他一切都很好。如果我想在
x[“timezone”]
获取的时区中格式化
dateobjf
,我该怎么做
x[“timezone”]
返回类似于
19800的内容
我相应地编辑了我的答案。同样是的,我知道时区是+5.5h,这是印度的时区。最后一个问题,如果我想从x[“timezone”]得到像
gmt+5:30
这样的时区,我该怎么做?