Skip to content

Instantly share code, notes, and snippets.

@taylanpince
Created June 26, 2019 19:01
Show Gist options
  • Save taylanpince/7b6b613029738e280032ece30b6676dd to your computer and use it in GitHub Desktop.
Save taylanpince/7b6b613029738e280032ece30b6676dd to your computer and use it in GitHub Desktop.
Aventri Attendee List Generator
#!/usr/bin/env python3
import csv
import re
import sys
from faker import Faker
fake = Faker()
ADDRESS_RE = re.compile(r'^(.*?), ([A-Z]{2}) ([0-9]{5})$')
FIELDS = [
'Email Address',
'Other Identifier',
'Prefix (Mr, Mrs, Dr etc)',
'First Name',
'Middle Name',
'Last Name',
'Suffix',
'Job Title',
'Company',
'Address Line 1',
'Address Line 2',
'Address Line 3',
'City',
'US State',
'State/County/Province (Non-US)',
'Zip (Postal Code)',
'Country',
'Work Phone',
'Extension',
'Fax',
'Mobile Phone',
'cc email',
'Skype/IM/Twitter ID'
]
US_STATES = {
'AL': 'Alabama',
'AK': 'Alaska',
'AZ': 'Arizona',
'AR': 'Arkansas',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DE': 'Delaware',
'FL': 'Florida',
'GA': 'Georgia',
'HI': 'Hawaii',
'ID': 'Idaho',
'IL': 'Illinois',
'IN': 'Indiana',
'IA': 'Iowa',
'KS': 'Kansas',
'KY': 'Kentucky',
'LA': 'Louisiana',
'ME': 'Maine',
'MD': 'Maryland',
'MA': 'Massachusetts',
'MI': 'Michigan',
'MN': 'Minnesota',
'MS': 'Mississippi',
'MO': 'Missouri',
'MT': 'Montana',
'NE': 'Nebraska',
'NV': 'Nevada',
'NH': 'New Hampshire',
'NJ': 'New Jersey',
'NM': 'New Mexico',
'NY': 'New York',
'NC': 'North Carolina',
'ND': 'North Dakota',
'OH': 'Ohio',
'OK': 'Oklahoma',
'OR': 'Oregon',
'PA': 'Pennsylvania',
'RI': 'Rhode Island',
'SC': 'South Carolina',
'SD': 'South Dakota',
'TN': 'Tennessee',
'TX': 'Texas',
'UT': 'Utah',
'VT': 'Vermont',
'VA': 'Virginia',
'WA': 'Washington',
'WV': 'West Virginia',
'WI': 'Wisconsin',
'WY': 'Wyoming',
'DC': 'District of Columbia',
'MP': 'Northern Mariana Islands',
'PW': 'Palau',
'PR': 'Puerto Rico',
'VI': 'Virgin Islands',
}
FIELD_GROUPINGS = dict((
('Email Address', 'mail'),
('Prefix (Mr, Mrs, Dr etc)', 'prefix'),
('First Name', 'first_name'),
('Last Name', 'last_name'),
('Job Title', 'job'),
('Company', 'company'),
('Address Line 1', 'address'),
('City', 'city'),
('US State', 'state'),
('Zip (Postal Code)', 'zip_code'),
('Country', 'country'),
('Work Phone', 'work_phone'),
('Mobile Phone', 'mobile_phone'),
('Extension', 'extension'),
))
def new_profile():
profile = fake.profile()
prefix = 'Mrs' if profile.get('sex') == 'F' else 'Mr'
names = profile.get('name').split(' ')
first_name = names[0]
last_name = names[-1]
address, state_info = profile.get('address').split('\n')
address_match = ADDRESS_RE.match(state_info)
if address_match is None:
return None
city, state, zip_code = address_match.groups()
work_phone = fake.phone_number()
extension = ''
if len(work_phone.split('x')) > 1:
work_phone, extension = work_phone.split('x')
mobile_phone = fake.phone_number()
profile.update({
'first_name': first_name,
'last_name': last_name,
'prefix': prefix,
'address': address,
'city': city,
'state': US_STATES[state],
'zip_code': zip_code,
'work_phone': work_phone,
'mobile_phone': mobile_phone,
'country': 'United States',
'extension': extension,
})
profile_output = {}
for field in FIELDS:
matching = FIELD_GROUPINGS.get(field, None)
if matching is None:
continue
profile_output[field] = profile.get(matching)
return profile_output
def generate_attendee_list(output_file_path, limit):
with open(output_file_path, 'w') as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=FIELDS)
writer.writeheader()
total = 0
while total < limit:
profile = new_profile()
if profile is None:
continue
writer.writerow(profile)
total += 1
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Please provide an output file path")
sys.exit(0)
limit = 100
try:
limit = int(sys.argv[2])
except:
pass
print("Generating %d attendees..." % limit)
generate_attendee_list(sys.argv[1], limit)
print("Done!")
@taylanpince
Copy link
Author

taylanpince commented Jun 26, 2019

Fake attendee list generator for Aventri. Depends on Faker.

Usage is: ./aventri_attendee_generator.py [output_filename] [number of attendees (optional, defaults to 100)].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment