Skip to main content

eams-attendee-upload.py (Source)

import pandas as pd
from trans import trans
import re
def make_username(name):
    return trans(re.sub(r'\W','',name).lower())
def fix_person(d):
    names = d['alternatename'].split(' ')
    d['firstname'] = names[0]
    d['lastname'] = ' '.join(names[1:])
    d['username'] = make_username(d['alternatename'])
    return d
import csv
import re
fields = {
    'alternatename': 'Your name',
    'institution': 'Your affiliation',
    'email': 'Your email address',
}
people = []
def load_file(filename,last_name=None):
    people = []
    with open(filename) as f:
        r = csv.DictReader(f)
        for row in r:
            d = {k:row[fields[k]] for k in fields.keys()}
            fix_person(d)
            if last_name is not None and d['lastname'].lower()==last_name.lower():
                break
            people.append(d)
    return people
fieldnames = ['alternatename', 'institution', 'email', 'firstname', 'lastname', 'username','cohort1']
def output_people(people,filename):
    with open(filename,'w') as f:
        w = csv.DictWriter(f,fieldnames=fieldnames)
        w.writeheader()
        for p in people:
            p['cohort1'] = f'participants{year}'
            w.writerow(p)
last_uploaded_name = None   # The name of the last person I uploaded, so I produce a CSV file only containing new people since then
new_people = load_file(FORM_FILE,last_uploaded_name)
output_people(new_people,'user-upload.csv')