Skip to main content (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()}
            if last_name is not None and d['lastname'].lower()==last_name.lower():
    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)
        for p in people:
            p['cohort1'] = f'participants{year}'
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)