Skip to content

Instantly share code, notes, and snippets.

@bmaurer
Created January 27, 2017 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmaurer/765f66abeb8db121234244b7e5a23d3b to your computer and use it in GitHub Desktop.
Save bmaurer/765f66abeb8db121234244b7e5a23d3b to your computer and use it in GitHub Desktop.
address printer
import csv
import pprint
f = open('/tmp/test', 'r')
reader = csv.DictReader(f, dialect='excel-tab')
def mailTitle(t):
if (t == 'Hon.'): return 'The Hon.'
return t
def mailFormat(t, first, middle, last):
return ' '.join( [x for x in [t, first, middle, last] if x != ''])
print '\t'.join(["Name", 'Address1', 'Address2', 'City', 'State/Region', 'Postal Code', 'Country'])
for r in reader:
first = (r['First Name'] or "").strip()
last = (r['Last Name'] or "").strip()
middle = (r['Middle Name'] or "").strip()
title = mailTitle((r['Title'] or "").strip())
pfirst = (r['Partner First Name'] or "").strip()
plast = (r['Partner Last Name'] or "").strip()
pmiddle = (r['Partner Middle Name'] or "").strip()
ptitle = mailTitle((r['Partner Title'] or "").strip())
fullname = mailFormat(title, first, middle, last)
if pfirst:
fullname += ' and ' + mailFormat(ptitle, pfirst, pmiddle, plast)
print '\t'.join([ x or '' for x in [fullname, r['Address1'], r['Address2'], r['City'], r['State/Region'], r['Postal Code'], r['Country']]])
#pprint.pprint(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment