Home » Configs » Twidge, twitter, mrtg and a little shell scripting to graph workouts

Twidge, twitter, mrtg and a little shell scripting to graph workouts

Twidge, twitter, mrtg and a little shell scripting to graph workoutsHere’s a script using Twidge, twitter, mrtg and a little shell scripting to graph workouts.

Twidge, twitter, mrtg and a little shell scripting to graph my workouts

I decided to start working out.  Ok, you can get off the floor now. I am working out. I have a really cool, entry level elliptical, the Schwinn 420.

The only problem with the Schwinn 420 is that it’s electronic console does NOT connect to the web. I decided to combat this by tweeting my workouts and having my linux box grab that data and dump it into some mrtg graphs.

First thing I did was setup a new twitter account (@johnsworkout) and follow it with my @beck_on_tech account.

Then I setup twidge, the command line twitter client, on my linux box using my @johnsworkout account.

When I workout I send a message to @johnsworkout with my weight, time on elliptical, distance and calories burned or wtdc as I remember it.

I run a script from cron every 2 hours.

# crontab -l
15 */2 * * *  /home/jbeck/scripts/workout-tweet.sh

# vi worktout-tweet.sh

#!/bin/sh
TWEETDATA=`twidge lsrecent -su |grep -i johnsworkout`
if [ “$TWEETDATA” != “” ]; then
    echo $TWEETDATA > /tmp/workout.txt
else
    exit 1
fi

This script looks at recent tweets from my @beck_on_tech account and filters for posts containing johnsworkout, then dumps that line to a file in /tmp. There’s also a tiny subroutine that exits if there is no data, so the file doesn’t get overwritten with emptyness.

Then MRTG handles the rest.

Below is the relevant snippets of my workout-mrtg.cfg file:

Options[weight]:gauge, nopercent, absolute, growright,noo
Target[weight]: `cat /tmp/workout.txt |awk ‘{print $3}’;cat /tmp/workout.txt |awk ‘{print $3}’`
MaxBytes[weight]: 300
Title[weight]: Weight

PageTop[weight]:
YLegend[weight]: Pounds

ShortLegend[weight]: lb
 
Options[time]:gauge, nopercent, absolute, growright,noo
Target[time]: `cat /tmp/workout.txt |awk ‘{print $4}’;cat /tmp/workout.txt |awk ‘{print $4}’`
MaxBytes[time]: 90
Title[time]: Time on elliptical
PageTop[time]:
YLegend[time]: Minutes
ShortLegend[time]: min
 
Options[distance]:gauge, nopercent, absolute, growright,noo
Target[distance]: `cat /tmp/workout.txt |awk ‘{print $5}’;cat /tmp/workout.txt |awk ‘{print $5}’`
MaxBytes[distance]: 90
Title[distance]: Distance on elliptical
PageTop[distance]: 

YLegend[distance]: Miles

ShortLegend[distance]: mi
 
Options[calories]:gauge, nopercent, absolute, growright,noo
Target[calories]: `cat /tmp/workout.txt |awk ‘{print $6}’;cat /tmp/workout.txt |awk ‘{print $6}’`
MaxBytes[calories]: 1000
Title[calories]: Calories burned
PageTop[calories]:

YLegend[calories]: Calories

ShortLegend[calories]: cal

As always, if you’ve got recommendations or a better way, I’m all ears


As an Amazon Associate I earn from qualifying purchases. Read our Privacy Policy for more info.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.