<commit_before>#!/usr/bin/env python
#import getpass

#defaults write com.pivotaltracker name <name>
#defaults write com.pivotaltracker pass <<PASSWORD>>
#defaults write com.pivotaltracker project <project_id>
#defaults write com.pivotaltracker query <query>
#defaults write com.pivotaltracker thl_list <The Hit List list name>

try:
	from pytracker import Tracker
	from pytracker import Story
	from pytracker import HostedTrackerAuth
except ImportError:
	exit('Fatal Error: Requires pytracker module. http://code.google.com/p/pytracker/')

try:
	import pydefaults
except ImportError:
	exit('Fatal Error: Requires pydefaults module. https://github.com/kfdm/pydefaults/')

settings = pydefaults.database('com.pivotaltracker')


import TheHitList
from extra.Terminal import TerminalController
term = TerminalController()
def found(string): print term.render('${BOLD}${RED}Found${NORMAL} %s'%string)
def adding(string): print term.render('${BOLD}${YELLOW}Adding${NORMAL} %s'%string)

def add_story(story,list):
	'''
	Add a PT Story to a THL List
	@param story: PT Story
	@param list: THL List
	'''
	for task in list.tasks():
		if task.notes == story.url:	
			found(task.title)
			return
	adding(story.name)
	newtask = TheHitList.Task()
	newtask.title = ('%s /Pivotal'%(story.name)).encode('utf8')
	newtask.notes = story.url.encode('utf8')
	list.add_task(newtask)

#Talk to Tracker
auth = HostedTrackerAuth(settings['login'], settings['pass'])
tracker = Tracker(int(settings['project_id']), auth)
stories = tracker.GetStories(settings['query'])

#Talk to THL
thl = TheHitList.Application()
list =  thl.find_list(settings['thl_list'].encode('utf-8'))
print '' #Line spacer
if list:
	for story in stories:
		add_story(story,list)<commit_msg>Make the Pivotal Tracker simpler and remove dependency on my other module<commit_after>#!/usr/bin/env python
# Example for importing PivotalTracker stories into THL

import commands
import TheHitList
try:
	from pytracker import Tracker
	from pytracker import Story
	from pytracker import HostedTrackerAuth
except ImportError:
	exit('Fatal Error: Requires pytracker module. http://code.google.com/p/pytracker/')

# Read in configuration information from git's configuration files
# To set, from the shell you can use
# git config <key name> <value>
# git config thl.list tasks
PT_LOGIN = commands.getoutput('/usr/local/bin/git config --get pivotal.login')
PT_PASS = commands.getoutput('/usr/local/bin/git config --get pivotal.password')
PT_PROJECT_ID = commands.getoutput('/usr/local/bin/git config --get pivotal.projectid')
PT_QUERY = commands.getoutput('/usr/local/bin/git config --get pivotal.query')
THL_LIST = commands.getoutput('/usr/local/bin/git config --get thl.list')

from extra.Terminal import TerminalController
term = TerminalController()
def found(string): print term.render('${BOLD}${RED}Found${NORMAL} %s'%string)
def adding(string): print term.render('${BOLD}${YELLOW}Adding${NORMAL} %s'%string)

def add_story(story,list):
	'''
	Add a PT Story to a THL List
	@param story: PT Story
	@param list: THL List
	'''
	for task in list.tasks():
		if task.notes == story.url:	
			found(task.title)
			return
	adding(story.name)
	newtask = TheHitList.Task()
	newtask.title = ('%s /Pivotal'%(story.name)).encode('utf8')
	newtask.notes = story.url.encode('utf8')
	list.add_task(newtask)

#Talk to Tracker
auth = HostedTrackerAuth(PT_LOGIN, PT_PASS)
tracker = Tracker(int(PT_PROJECT_ID), auth)
stories = tracker.GetStories(PT_QUERY)

#Talk to THL
thl = TheHitList.Application()
list =  thl.find_list(THL_LIST)
print '' #Line spacer
if list:
	for story in stories:
		add_story(story,list)
{'fraction_non_alphanumeric': 0.1284808381582575, 'fraction_numerical': 0.0013785497656465398, 'mean_word_length': 5.572463768115942, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '483850', 'n_tokens_mistral': 1253, 'n_tokens_neox': 1209, 'n_words': 323}