Created
January 27, 2017 06:03
-
-
Save bmaurer/765f66abeb8db121234244b7e5a23d3b to your computer and use it in GitHub Desktop.
address printer
This file contains hidden or 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 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