Surfs Up

I've just started learning how to surf. Using the website Magic Seaweed to look at conditions of the waves is vital to having a good time. My local beach break varies in conditions from pan flat to monster killer waves with ripping tidal flows. Now I'm too lazy to look at the website every day so I've written a script that lives on my server and scrapes information from Magic Seaweed and also tidetimes.org For tidal information. If a few conditions are met that make the surf ideal for me then the script sends me an email. Here is a walk through of the code

First the required imports.

  • requests deals with making http requests to websites and returning the information in a useable format.
  • beautiful soup deals with scraping the html on a page and searching for tags.
  • datetime and time for finding the time and date!
  • smtplib for sending an email.

Now define the urls for magic seaweed and tidetimes.org splitting them into a root address and a sub address in case changes are needed in future.

The email_alert function uses a Google api to send an email from an address I keep especially for automated alerts. This method avoids having to set up something like sendmail on my server. More details can be found in this post

A small function that takes a url as input, gives it to requests to get the page and feeds this to beautiful soup to parse. This is then returned from the function.

During the week I can only surf during the evenings so the next two functions are needed.

A small function to find what day it is tomorrow.

A small function that returns true if it its input is a weekday.

I now had to inspect the html of the websites to find the particular tags that contained the information I needed. For example, the time for low tide is found between the ".tag > span" tags.

This function returns the low tide times from the tidetimes.org website.

This function returns the wind speed at 3 hourly intervals throughout the day from magic seaweed.

This function returns the size of the waves from magic seaweed.

Now call the functions defined above to find the information we need.

If it's a weekday look to see if low tide is around 11-1. This means the tide will be ideal by the time I get there. The check if the waves are between 2-4 feet and the wind is less than 15 mph. If all these conditions are true then return true. If it's not a weekday then the surf conditions could be good at any time during the day and we have to check these conditions separately.

Send the email message.

Comments