Created
April 6, 2021 13:30
-
-
Save prehensilecode/9573330cb8e4cd1546a7ccd434d625a8 to your computer and use it in GitHub Desktop.
Take a Listserv subscriber report and extract just full names and emails
This file contains 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
#!/usr/bin/env python3 | |
import sys | |
import os | |
import csv | |
import argparse | |
import pathlib | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-d', '--debug', action='store_true', help='Debug') | |
parser.add_argument('-i', '--infile', type=argparse.FileType('r'), help='CSV file from LISTSERV') | |
parser.add_argument('-o', '--outfile', type=argparse.FileType('w'), help='Output CSV file') | |
args = parser.parse_args() | |
debug_p = args.debug | |
if debug_p: | |
print(args) | |
reader = csv.reader(args.infile) | |
subscribers = [] | |
counter = 0 | |
for row in reader: | |
if counter == 0: | |
# skip first line | |
counter += 1 | |
continue | |
else: | |
subscribers.append({'Full name': ' '.join(row[0].split(' ')[1:]), 'Email': row[0].split(' ')[0]}) | |
counter += 1 | |
if debug_p: | |
print(subscribers) | |
writer = csv.DictWriter(args.outfile, fieldnames=['Full name', 'Email']) | |
writer.writeheader() | |
writer.writerows(subscribers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment