Created
July 14, 2014 18:05
-
-
Save paltman/1a17b01f46b5f70dc2f1 to your computer and use it in GitHub Desktop.
This file contains 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
import decimal | |
import sys | |
from collections import defaultdict | |
import requests | |
BASE_URL = "https://api.trello.com" | |
TOKEN = "46815a201a51fa6e8ec61285477b7851086b3b842dc84caaf391376b8855d6db" | |
KEY = "4775587938cd6a6fbc5c2c0acf1185a1" | |
BOARD_ID = "5230f1ae14469f647800150c" | |
def build_content(files): | |
content = "" | |
for fname in files: | |
content += open(fname, "rb").read() | |
if content[-1] != "\n": | |
content += "\n" | |
return content | |
def fetch_cards(): | |
url = "https://api.trello.com/1/boards/{0}/cards?token={1}&key={2}&filter=all".format( | |
BOARD_ID, | |
TOKEN, | |
KEY | |
) | |
return requests.get(url).json() | |
def collapse_sort_entries(content): | |
lines = [ | |
line.split(" - ") | |
for line in | |
content.split("\n") | |
if len(line.strip()) > 0 | |
] | |
entries = defaultdict(lambda: []) | |
for line in lines: | |
entries[line[1]].append(decimal.Decimal(line[0])) | |
summed_entries = [ | |
(key, sum(entries[key])) | |
for key in entries.keys() | |
] | |
return summed_entries | |
def main(): | |
files = sys.argv[1:] | |
if len(files) == 0: | |
sys.exit("Must provide files to process") | |
content = build_content(files) | |
summed_entries = collapse_sort_entries(content) | |
total = sum([se[1] for se in summed_entries]) | |
summed_entries.sort() | |
cards = fetch_cards() | |
for entry in summed_entries: | |
if entry[0].startswith("#"): | |
short_url = "" | |
for card in cards: | |
if int(card["idShort"] == int(entry[0].replace("#", ""))): | |
short_url = card["shortUrl"] | |
else: | |
short_url = "" | |
print "* {0} - {1} - {2}".format(str(entry[1]).rjust(4), entry[0].rjust(4), short_url) | |
print "\nTotal: {0} hours".format(total) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment