(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
Created
March 8, 2012 18:46
-
-
Save leetrout/2002627 to your computer and use it in GitHub Desktop.
Command line tool for Pivotal Tracker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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