Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save prehensilecode/9573330cb8e4cd1546a7ccd434d625a8 to your computer and use it in GitHub Desktop.
Save prehensilecode/9573330cb8e4cd1546a7ccd434d625a8 to your computer and use it in GitHub Desktop.
Take a Listserv subscriber report and extract just full names and emails
#!/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