Skip to content

Instantly share code, notes, and snippets.

@leetrout
Created March 8, 2012 18:46
Show Gist options
  • Select an option

  • Save leetrout/2002627 to your computer and use it in GitHub Desktop.

Select an option

Save leetrout/2002627 to your computer and use it in GitHub Desktop.
Command line tool for Pivotal Tracker
(eex)vader:pt lee$ alias ptls="python ~/code/scripts/ptcli.py"
(eex)vader:pt lee$ ptls 
Your Current Work on PivotalTracker
[#31118493] (started) User is unable to reset password
[#38774275] (delivered) Bill Management page not showing Consumption.
[#31026073] (started) ?next is not preserved on log in
[#37554097] (unstarted) Total consumption cost error
[#38713035] (unscheduled) Ion - Tests - Helpers
#!/usr/bin/env python
"""Command Line Interface for PivotalTracker"""
from exceptions import SystemExit
#from optparse import OptionParser
import os
import urllib2
from xml.etree import ElementTree
# environment keys needed to access the PT api
environ_keys = [
'PT_TOKEN', # PT api token
'PT_PROJECT_ID', # PT project id
'PT_MYWORK_KEY' # string to use to filter (username or initials)
]
# PT object to hold our values after we ensure they are set
PT = {}
def my_work():
headers = {'X-TrackerToken': PT['PT_TOKEN']}
url = "http://www.pivotaltracker.com/services/v3/projects/\
%(PT_PROJECT_ID)s/stories?filter=" % PT
filter = "mywork:%(PT_MYWORK_KEY)s" % PT
url = url + urllib2.quote(filter)
req = urllib2.Request(url, headers=headers)
resp = urllib2.urlopen(req)
xml = ElementTree.fromstring(resp.read())
print("Your Current Work on PivotalTracker")
for story in xml.findall('story'):
print("[#%s] (%s) %s" % (story.find('id').text,
story.find('current_state').text,
story.find('name').text))
if __name__ == '__main__':
# get key values and setup our PT object
for key in environ_keys:
val = os.environ.get(key)
if val is None:
raise SystemExit("Missing environment var %s" % key)
PT[key] = val
my_work()
# this should be added in the future
#parser = OptionParser()
#parser.add_option("-m", "--method",
# dest="method", default='my_work',
# help='which method to call. Options are "my_work"')
#
#(options, args) = parser.parse_args()
#
#if options.method == 'my_work':
# my_work()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment