Skip to content

Instantly share code, notes, and snippets.

@h2rashee
Last active February 17, 2022 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h2rashee/f4d3f15a636b6386207f52b3dee17173 to your computer and use it in GitHub Desktop.
Save h2rashee/f4d3f15a636b6386207f52b3dee17173 to your computer and use it in GitHub Desktop.
Determining who hasn't renewed for the new year
import csv
import sys
DEBUG = False
# We process two input CSV files that have the following field names:
LAST_NAME_FIELD = 'Last Name'
FIRST_NAME_FIELD = 'First Name'
EMAIL_FIELD = 'Email Address'
CELL_PHONE_FIELD = 'Cell Phone Number'
def main(old_file, new_file):
email_store = {}
name_store = {}
phone_number_store = {}
try:
with open(new_file) as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
line_count = line_count + 1
continue
full_name = '{} {}'.format(row[FIRST_NAME_FIELD], row[LAST_NAME_FIELD]).lower()
email = row[EMAIL_FIELD].lower()
phone_number = sanitize_phone_number(row[CELL_PHONE_FIELD])
email_store[email] = full_name
name_store[full_name] = email
phone_number_store[phone_number] = full_name
line_count += 1
if DEBUG:
print('Processed {} lines'.format(line_count))
with open(old_file) as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
line_count = 0
for row in csv_reader:
if line_count == 0:
line_count = line_count + 1
continue
full_name = '{} {}'.format(row[FIRST_NAME_FIELD], row[LAST_NAME_FIELD]).lower()
email = row[EMAIL_FIELD].lower()
phone_number = sanitize_phone_number(row[CELL_PHONE_FIELD])
line_count += 1
if email in email_store:
if DEBUG:
print('{} in email store'.format(email))
continue
if full_name in name_store:
if DEBUG:
print('{} in full name store'.format(full_name))
continue
if phone_number in phone_number_store:
if DEBUG:
print('{} in phone number'.format(phone_number))
continue
print('{},{},{},{}'.format(row[LAST_NAME_FIELD], row[FIRST_NAME_FIELD], row[EMAIL_FIELD], row[CELL_PHONE_FIELD]))
if DEBUG:
print('Processed {} lines'.format(line_count))
except FileNotFoundError:
print("ERROR: No such file exists;", old_file, new_file)
except Exception as e:
print("ERROR: Something went wrong:", e)
chars_to_sanitize = ['(', ')', ' ', '-', '.']
def sanitize_phone_number(str):
for bad_char in chars_to_sanitize:
str.replace(bad_char, '')
return str
# Driver
main(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment