Last active
August 16, 2018 13:42
-
-
Save stefanor/7b3942d2cf2171d9b13f12e5993fb22f 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
#!/usr/bin/env python3 | |
import argparse | |
import csv | |
def main(): | |
p = argparse.ArgumentParser() | |
p.add_argument('input', type=argparse.FileType('r'), | |
help='Input Ti.to CSV') | |
args = p.parse_args() | |
r = csv.reader(args.input) | |
headers = next(r) | |
by_ref = {} | |
for row in r: | |
as_dict = dict(zip(headers, row)) | |
ref = as_dict['Order Reference'] | |
if ref not in by_ref: | |
if as_dict['Can we release your full name, email address, and company name to sponsors?']: | |
email = as_dict['Ticket Email'] | |
else: | |
email = '' | |
by_ref[ref] = { | |
'name': as_dict['Ticket Full Name'], | |
'email': email, | |
'company': as_dict['Company / Organization'], | |
'type': 'attendee', | |
} | |
if 'Corp' in as_dict['Ticket']: | |
by_ref[ref]['type'] = 'corporate' | |
if 'Saturday' in as_dict['Ticket']: | |
by_ref[ref]['type'] = 'saturday' | |
if 'Sunday' in as_dict['Ticket']: | |
by_ref[ref]['type'] = 'sunday' | |
if 'Opening' in as_dict['Ticket']: | |
by_ref[ref]['type'] = 'party' | |
if 'Sponsorship' in as_dict['Ticket']: | |
by_ref[ref]['type'] = 'exhibitor' | |
if 'Speaker' in as_dict['Ticket']: | |
by_ref[ref]['type'] = 'speaker' | |
write_attendees(by_ref, 'attendee') | |
write_attendees(by_ref, 'corporate') | |
write_attendees(by_ref, 'exhibitor') | |
write_attendees(by_ref, 'party') | |
write_attendees(by_ref, 'saturday') | |
write_attendees(by_ref, 'speaker') | |
write_attendees(by_ref, 'sunday') | |
def write_attendees(people, type_): | |
with open('{}.csv'.format(type_), 'w') as f: | |
w = csv.writer(f) | |
w.writerow(('Ticket Full Name', 'Ticket Email', 'Company / Organization')) | |
for person in people.values(): | |
if person['type'] != type_: | |
continue | |
if not person['name']: | |
continue | |
w.writerow(( | |
person['name'], | |
person['email'], | |
person['company'], | |
)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment