為魔法海藻提供了基本的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鍵