Import CSV to FogBugz

We needed to add 100+ bugs to our FogBugz database today, and I figured it would be easier to write a tool to import them than to enter them all by hand. Thank goodness for the FogBugz XML API and the Python library.

This tool reads from a CSV file (with header row) and adds the case via the API.

Example CSV data:

Category,Title,Project,Assigned To,Priority,Status,Milestone
Feature,"Report is incorrect",Website,Unassigned,3 - Very Important,Active,Product Backlog
Feature,"Login fails",Website,,3 - Very Important,Active,Product Backlog
Feature,"Logo is incorrect",Website,Unassigned,3 - Very Important,Active,Product Backlog
import csv
import sys
import os
from fogbugz import FogBugz

if len(sys.argv) < 5:
	sys.exit("Usage: python <URL> <USER> <PASSWORD> <CSV FILE>")

# Make sure the CSV file exists
if not os.path.exists(sys.argv[4]):
    sys.exit('ERROR: CSV file %s was not found!' % sys.argv[4])

fburl 	= sys.argv[1]
fbuser 	= sys.argv[2]
fbpass 	= sys.argv[3]	 
csvfile = sys.argv[4]

# Connect to FogBugz server
fb = FogBugz(fburl)
fb.logon(fbuser, fbpass)

# For each row, print key data and add to FogBugz
with open(csvfile, 'rb') as csvfile:
	csvreader = csv.DictReader(csvfile)
	for row in csvreader:
		print "Adding:"
		print "    Title	: " + row["Title"]
		print "    Project	: " + row["Project"]
		print "    Category	: " + row["Category"]
		print "    Milestone	: " + row["Milestone"]
		print "======================="["Title"],

About Kevin

Kevin Jarnot is a technologist who lives just South of Boston, MA. He is currently employed as Chief Technology Officer at DebtX, a financial services technology company based in Boston.
This entry was posted in Tech. Bookmark the permalink.

Leave a Reply