Last Updated: February 25, 2016
·
642
· Lorin Hochstein

Querying pivotal tracker from command-line

I use this script to be query pivotal tracker from the command line

import requests
import sys
from lxml import etree

TOKEN = 'YOUR TOKEN GOES HERE'
PROJECT_URL = 'YOUR PROJECT URL GOES HERE'


def main(args):
    query = ' '.join(args)
    xml = get_stories(query)
    parse(xml)


def parse(xml):
    root = etree.fromstring(xml)
    for story in root.getchildren():
        id = story.find('id').text
        name = story.find('name').text
        print "%s %s" % (id, name)

def get_stories(query, token=TOKEN, url=PROJECT_URL):
    payload = {'filter': query}
    headers = {'X-TrackerToken': token}
    response = requests.get(url, params=payload, headers=headers)
    return response.content

if __name__ == '__main__':
    main(sys.argv[1:])

Usage is like this:

$ pivotal state:unscheduled,unstarted,started label:myproject