Tag: beautifulsoup

Creating a Google calendar training plan

My wife and I are both training for a triathlon right now. She found a training plan online that she wanted to follow, but thought she would actually stick to it if it was on her Google calendar. With a little Python, I was able to do this in a couple of hours.

The first step was getting the training plan from the web. This was fairly straightforward to accomplish with BeautifulSoup, a popular Python package for web scraping (extracting data from a web site). I then moved the data into a Pandas DataFrame, which I find easy to work with. The data came in a daily format, even though some days had two workouts at two different times. So I parsed through the data to look for “a.m.” or “p.m.” to split the workouts into their respective time.

There were some oddities to how the page was laid out. For example, in the text of swim workouts it would refer to a warmup type by number which was at the bottom of the page. So I had to make a few adjustments to deal with these ways that the layout was a little odd but it was not too much work.

After exporting this into an cvs file and opening in Excel, I added a column for date (setting the race day appropriately and working backwards). Morning and evening workouts were given a time of 6am and 5pm respectively. Google makes the final step of creating a new calendar from this cvs file easy.

In about two hours, I was able to turn this web page training plan into a Google Calendar!

 

Navigation