Created
April 10, 2014 20:35
-
-
Save apendleton/10420672 to your computer and use it in GitHub Desktop.
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, 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