The goal? Make a simple twitter client that would share my exercise information - what cardio I did, how long I did it, and the distance I went because of it.
Several of my coworkers have this done for them via a website service to track their running - unfortunately I can't run with them due to an ankle injury years ago. I can't take the high impact constantly on that ankle that you get from long distance runs. Instead I plan on getting healthy via biking and rowing - tonight I biked.
Of course, this is part one of a much larger project, but the tweeting aspect of the program was a simple part that could act as a stand alone program. There are a few other features I plan on adding to this over the coming month (but only now and then).
The code:
The result:#! /usr/bin/python
import twitterfrom getpass import getpass
def createApp(username, password):twitterSystem = twitter.Api(username, password)return twitterSystem
user = raw_input("Enter your username - ")pword = getpass("Enter your password - ")
twitterSystem = createApp(user, pword)
action = raw_input("What kind of cardio did you do? (Past tense, lower case) ")miles = raw_input("How many miles did you go? ")time_done = raw_input("How many minutes did it take you? ")
message = "I " + action + " " + miles + " miles in " + time_done + " minutes."
print "Posting..."
twitterSystem.PostUpdate(message)
print "Posted!"
Take note: I couldn't get the "posted via web" to change to the program's name. The formatting is ugly, and I'd like to make it a little more flexible. Other things I could do? I could make it function based, so I can easily apply it to another program.
The formatting is quick and dirty - but that's how some of these quick scripts will come out for March Madness.
Tomorrow's hopefully will be a lot cleaner.
No comments:
Post a Comment