Skip to content

Instantly share code, notes, and snippets.

@apendleton
Created April 10, 2014 20:35
Show Gist options
  • Save apendleton/10420672 to your computer and use it in GitHub Desktop.
Save apendleton/10420672 to your computer and use it in GitHub Desktop.
import csv, re
SEARCH_TERMS = [re.compile(term, re.I) for term in [r"(?<!white )house", "HFAC", "Congressman", "Congresswoman", "Congressional", "Senate", "Senator"]]
SEARCH_COLS = ["contact_title", "contact_name", "contact_office", "contact_agency"]
csv_infile = open('contacts.csv', 'rb')
csv_in = csv.DictReader(csv_infile)
csv_outfile = open('contacts_filtered.csv', 'wb')
csv_out = csv.DictWriter(csv_outfile, csv_in.fieldnames)
csv_out.writeheader()
for row in csv_in:
if any([term.search(row[col]) for term in SEARCH_TERMS for col in SEARCH_COLS]):
csv_out.writerow(row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment