Package: magicseaweed
python-magicseaweedProvides basic API toMagic 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.Installpip install magicseaweedRequirementsYou need an API key to use it. Check the notes section for signup info.UsageBasic UseNo 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:importmagicseaweedapi_key=os.environ.get('MSW_API_KEY')ponce_id=348bethune_id=371ponce_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)forforecastinbethune_future.data:print(forecast.attrs)print(forecast.get_chart_url('swell'))TheMSW_forecast()class has a few optional parameters. Your API key, and a spot id are the only required parameters.Use theforecast.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()forforecastinponce_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"
}
}]AdvancedclassMSW_Forecast(api_key, spot_id, fields, units)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:api_key- Your API key fromhttps://magicseaweed.com/developer/forecast-apispot_id- The ID of a location, available from the URL when visiting the corresponding spot on the Magic Seaweed website. IE '616' inhttp://magicseaweed.com/Pipeline-Backdoor-Surf-Report/616/fields- (optional) Comma separated list of fields to include in the request URL. Defaults to none, which returns all information. Specifying fields may reduce response time. Example: ['timestamp','wind.*','condition.temperature']units- (optional) A string of the preferred unit of measurement. Defaults to unit at location of spot_id. eu, uk, us are availableMethodsget_current()- This fucntion returns a single datapoint representing the forecast providedd by MSW if you called the API withstart=dt.now().timestamp()andend=dt.now().timestamp(). Returns aForecastDataPoint.get_future()- This fucntion returns a group of datapoints, beginning with the current forecast and each representing the forecast for a 3 hour period over a 96 hour series (4 days). Returns aForecastDataBlock.get_all()- This function returns the default MSW response if no time parameters are added. This is usually 5 days of forecasts in 3 hour intervals. You may receive some forecasts for expired times. Returns aForecastDataBlock.get_manual(start, end)- This fucntion allows requests for manually selected periods of time using the start and end parameters. Returns aForecastDataBlock.start- A local timestamp from which the forecast should being. Example:datetime.now().timestamp()end- A local timestamp from which the forecast should end. Example:datetime.now().timestamp()classForecastDataBlockContains data about a forecast over time and the HTTP response from Magicseaweed.Attributeshttp_headersA dictionary of response headers.responseThe Response object returned from requests request.get() method. Seehttps://requests.readthedocs.org/en/latest/api/#requests.ResponsesummaryA human-readable text summary of this data block.dataAn array ofForecastioDataPointobjects (see below), ordered by time.classForecastDataPointContains data about a forecast at a particular time and the HTTP response from Magicseaweed.Data points have many attributes, butnot all of them are always available. Some commonly used ones are:localTimestampThe time at which the forecast begins, adjusted for the spot's timezone.swell_maxBreakingHeightA numerical value representing the height of the maxmimum wave for this forecast.Attributeshttp_headersA dictionary of response headers.responseThe Response object returned from requests request.get() method. Seehttps://requests.readthedocs.org/en/latest/api/#requests.ResponsesummaryA human-readable text summary of this data point.dA dictionary of the JSON response from the MSW API.f_dA flattened dictionary of the the JSON response from the MSW API. Keys are compressed using the '_' character.attrsA human-readable form of the attributes from this forecast.Methodsget_swell_url()This fucntion returns a URL formatted for the swell direction of this forecast.get_wind_url()This fucntion returns a URL formatted for wind swell direction of this forecast.For a full list of ForecastDataPoint attributes and attribute descriptions, take a look at the table from the Magicseaweeddocumentation. NOTE: While the MSW API accepts fields in dot.notation, use snake_case to access these attributes in a ForecastDataPoint.DevelopmentPull requests welcome.DisclaimerNot affiliated with magicseaweed.com. Use at your own risk.TODO:Compile chart into animated GIFs for the ForecastDataBlocksObtain an API Key:The Magic Seaweed API is currently in beta. To obtain an API key, please follow the instructions available hereSign UpEmailgeneral@magicseaweed.comwith the following informationMention that you’ve read and agree our Terms and Conditions. We’ll be unable to offer access unless this is the case.A URL for your application if web basedYour business or personal nameA name for your application and some very basic detailsReferences:https://magicseaweed.com/developer/forecast-api