Provides basic API to Magic Seaweed.
Note: As of 7/8/2022, it was reported that Magicseaweed is not distributing new API keys. This package still works for those who have an API key. Magicseaweed has not stated when or if they will start distributing API keys again. Reference the "Obtain an API Key" section below if you'd like to contact them for more information.
pip install magicseaweed
No familiarity with the Magic Seaweed API is required to use this package. For reference, you can find their API documentation here: Magic Seaweed Docs. This package provides some default API interactions based on time.
To use the wrapper:
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'))
The MSW_forecast()
class has a few optional parameters. Your API key, and a spot id are the only required parameters.
Use the forecast.DataBlockType()
eg. current()
, future()
, all()
, manual()
, methods to load the data you are after.
current()
Returns a single forecast. All other methods return a block of forecasts.
future()
all()
manual()
The .data attributes for each DataBlock is a list of Forecast objects.
ponce_future = ponce_forecast.get_future()
for forecast in ponce_future.data:
print(forecast.summary)
Example API Response:
[{
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"
}
}]
This class is for interacting with the MSW API. You can use it's functions to get points or series of data for different time periods.
Parameters:
Methods
start=dt.now().timestamp()
and end=dt.now().timestamp()
. Returns a ForecastDataPoint.datetime.now().timestamp()
datetime.now().timestamp()
Contains data about a forecast over time and the HTTP response from Magicseaweed.
Attributes
Contains data about a forecast at a particular time and the HTTP response from Magicseaweed.
Data points have many attributes, but not all of them are always available. Some commonly used ones are:
Attributes
Methods
For a full list of ForecastDataPoint attributes and attribute descriptions, take a look at the table from the Magicseaweed documentation. NOTE: While the MSW API accepts fields in dot.notation, use snake_case to access these attributes in a ForecastDataPoint.
Pull requests welcome.
Not affiliated with magicseaweed.com. Use at your own risk.
The Magic Seaweed API is currently in beta. To obtain an API key, please follow the instructions available here Sign Up