为魔法海藻提供了基本的API。
注意:截至2022年7月8日,据报道,魔术师没有分发新的API键。此软件包仍然适用于具有API密钥的人。 Magicseaweed尚未说出什么时候或是否会再次分发API键。如果您想与他们联系以获取更多信息,请参考下面的“获得API密钥”部分。
pip install magicseaweed
使用此软件包不需要魔术海藻API。作为参考,您可以在此处找到他们的API文档:魔术海藻文档。该软件包提供了一些基于时间的默认API交互。
使用包装器:
import magicseaweed
api_key = os . environ . get ( 'MSW_API_KEY' )
ponce_id = 348
bethune_id = 371
ponce_forecast = MSW_Forecast ( api_key , ponce_id )
ponce_now = ponce_forecast . get_current ()
print ( ponce_now . attrs )
bethune_forecast = MSW_Forecast ( api_key , bethune_id )
bethune_future = bethune_forecast . get_future ()
print ( bethune_future . summary )
for forecast in bethune_future . data :
print ( forecast . attrs )
print ( forecast . get_chart_url ( 'swell' )) MSW_forecast()类有一些可选参数。您的API键,斑点ID是唯一必需的参数。
使用forecast.DataBlockType() current() , future() , all() , manual() ,加载您所追求的数据的方法。
current()返回单个预测。所有其他方法返回一个预测块。
future()all()manual()每个DataBlock的.DATA属性是预测对象的列表。
ponce_future = ponce_forecast . get_future ()
for forecast in ponce_future . data :
print ( forecast . summary )示例API响应:
[ {
timestamp : 1366902000 ,
localTimestamp : 1366902000 ,
issueTimestamp : 1366848000 ,
fadedRating : 0 ,
solidRating : 0 ,
swell : {
minBreakingHeight : 1 ,
absMinBreakingHeight : 1.06 ,
maxBreakingHeight : 2 ,
absMaxBreakingHeight : 1.66 ,
unit : "ft" ,
components : {
combined : {
height : 1.1 ,
period : 14 ,
direction : 93.25 ,
compassDirection : "W"
} ,
primary : {
height : 1 ,
period : 7 ,
direction : 83.37 ,
compassDirection : "W"
} ,
secondary : {
height : 0.4 ,
period : 9 ,
direction : 92.32 ,
compassDirection : "W"
} ,
tertiary : {
height : 0.3 ,
period : 13 ,
direction : 94.47 ,
compassDirection : "W"
}
}
} ,
wind : {
speed : 10 ,
direction : 85 ,
compassDirection : "W" ,
chill : 15 ,
gusts : 13 ,
unit : "mph"
} ,
condition : {
pressure : 1020 ,
temperature : 18 ,
unitPressure : "mb" ,
unit : "c"
} ,
charts : {
swell : "http://cdn.magicseaweed.com/wave/750/1-1366902000-1.gif" ,
period : "http://cdn.magicseaweed.com/wave/750/1-1366902000-2.gif" ,
wind : "http://cdn.magicseaweed.com/gfs/750/1-1366902000-4.gif" ,
pressure : "http://cdn.magicseaweed.com/gfs/750/1-1366902000-3.gif" ,
sst : "http://cdn.magicseaweed.com/sst/750/1-1366902000-10.gif"
}
} ] 该课程用于与MSW API互动。您可以使用其功能来获取不同时间段的点或一系列数据。
参数:
方法
start=dt.now().timestamp()和end=dt.now().timestamp() 。返回一个预先登机口。datetime.now().timestamp()datetime.now().timestamp() 包含有关随着时间的预测和Magicseaweed的HTTP响应的数据。
属性
包含有关特定时间预测的数据以及Magicseaweed的HTTP响应。
数据点具有许多属性,但并非所有属性始终可用。一些常用的是:
属性
方法
有关ForecastDataPoint属性和属性描述的完整列表,请查看Magicseaweed文档中的表格。注意:当MSW API接受点中的字段时,请使用snake_case在预测datapoint中访问这些属性。
拉动请求欢迎。
不隶属于magicseaweed.com。自行使用。
魔术海藻API目前正在Beta中。要获取API键