Surf Status Text Bot with Python

Berknorman
4 min readMar 23, 2021

This post previews a python-based SMS bot I built that sends users updates on surf spot conditions. This will mostly describe the process at a high level. Low level implementation details can be found in the github repo.

https://www.camwalkerphoto.com/surfing

Most surfers are on top of their local spot conditions, knowing when the next swell and wind window will be. But sometimes life gets in the way and we miss a much needed session. We get busy and forget that there might be favorable conditions or maybe we just miscalculate the upcoming surf data. Surf forecasting is, after all, a difficult task.

This is why Surfline is so great. They provide buoy, swell, wind, tide, and camera data for surf spots all over the world. For popular spots, they even have human reports twice a day. These human report use a 9 point scale ranging from “VERY POOR” all the way to “EPIC” to describe current spot conditions.

Example of a human Surfline report: https://www.surfline.com/surf-report/pelican-beach-park/584204214e65fad6a7709d12

The Surfline app does have a “Surf Alerts” feature (only for iOS and possibly only for premium members?) where you can select spots you like and have Surfline send you a push notification when that spot reaches some conditions you’ve specified based on the human report. However, I tend to ignore/disallow most push notifications on my phone and have noticed the Surfline one’s don’t always come through (potential user error). Also, I tend to be a bit more alert and responsive to texts. So, I built an SMS bot that pings users when their desired surf spots reach minimum condition thresholds based off of Surfline human reports.

There are 2 main processes to make this bot work:

  1. A Flask user sign up/location specification process
  2. A cron job that is checking for human report surf status updates

One other note about tooling is that the surf spot and condition information is retrieved using python’s request and BeautifulSoup libraries.

User Sign Up

In order to send a user condition updates, we need to know which spots the user is interested in. To do this, I created an sms Twilio client hosted by Flask that was capable of signing a user to updates from certain surf locations.

Currently this SMS interaction is instigated by a user sending any text (“hi” in this case). This should probably be changed to something a little more intuitive like have the user sign-up via a specific text command.

This user data is then saved to the “database”. Database is in quotations because it is currently just a pickle file of a dictionary with keys of surf locations and values of their conditions, last time they were updated, and which users are subscribed to them. If this were a larger scale project with hundreds of users, a more traditional database schema should be used, but the poor-mans database is sufficient for now.

A caveat to note about the sign up process is that not all surf locations have human reports associated with them. If that is the case the sign up bot will prompt the user to select a different location.

Cron job Status Updates

In order for subscribed users to receive spot status updates, a cron job is created that checks for status updates (every 5 minutes in the example below). If a surf spot’s condition status changes and the condition is greater than or equal to the threshold specified by the users subscribed to that spot, those users will receive a text.

*/5 * * * * source /path/to/surf/bot/virutalenv/bin/activate && python /path/to/cloned/repo/surf_bot/send_updates.py

The frequency of this cron job could be increased if you really wanted human report updates are soon as they are posted.

Closing thoughts

This is very much a quick POC/weekend project. My day job is as a Machine Learning Scientist so this was also just a nice way to explore some tools I don’t normally use. If enough people are interested in this, I’d be happy to spin up a full-time server to host this service. For the more tech-savvy readers, you can use the code to spin up your own surf bot or, even better, collaborate to make this a more extensive tool!

--

--

Berknorman

Machine Learning Scientist by day, Surfer by day