def main():
    with open(OUT_PATH, 'wb') as out_file:
        prefix = b'clients = Client.create!(['
        out_file.write(prefix)
        with security.open(IN_PATH, newline='') as in_file:
            in_file.readline(); in_file.readline()
            first_line = True
            for row in csv.DictReader(in_file):
                strip_all(row)
                if first_line:
                    first_line = False
                else:
                    out_file.write(b' ' * len(prefix))
                extract_contact_parts(row)
                extract_city_state(row)
                out_file.write(TEMPLATE.format(
                    business_name=e_to_e(row['Company Name (print your name)']),
                    address=row['Address'],
                    email='',
                    telephone=phone_letter_to_number(row['Telephone']),
                    comment=none_to_empty(row['Comments (Done?)']),
                    website='',
                    zipcode=calculate_zipcode(row),
                    contact_fname=row['contact_fname'],
                    contact_lname=row['contact_lname'],
                    contact_title=row['contact_title'],
                    city=row['City'],
                    state=row['State'],
                    status_type=calculate_status(row)).encode())
        out_file.seek(-3, io.SEEK_CUR)
        out_file.write(b'])')
        out_file.truncate()
def main():
    years_by_project = {name: set() for name in PROJECT_TYPES}
    with security.open(IN_PATH, newline='') as in_file:
        in_file.readline(); in_file.readline()
        for row in csv.DictReader(in_file):
            strip_all(row)
            for name, years in years_by_project.items():
                years.update(create_years(row[name]))
    with open(OUT_PATH, 'wb') as out_file:
        prefix = b'projects = Project.create!(['
        out_file.write(prefix)
        first_line = True
        for name, years in years_by_project.items():
            for year in years:
                if first_line:
                    first_line = False
                else:
                    out_file.write(b' ' * len(prefix))
                out_file.write(TEMPLATE.format(
                    year=year,
                    semester=PROJECT_TYPES[name].semester,
                    open_year=year,
                    open_month=PROJECT_TYPES[name].open,
                    open_day=1,
                    close_year=year,
                    close_month=PROJECT_TYPES[name].close,
                    close_day=1,
                    project_type_name=name).encode())
        out_file.seek(-3, io.SEEK_CUR)
        out_file.write(b'])')
        out_file.truncate()
def main():
    with open(OUT_PATH, 'wb') as out_file:
        out_file.write(b"priority_id = (Priority.find_by name: 'low').id\r\n")
        prefix = b'tickets = Ticket.create!(['
        out_file.write(prefix)
        with security.open(IN_PATH, newline='') as in_file:
            in_file.readline(); in_file.readline()
            first_line = True
            for row in csv.DictReader(in_file):
                strip_all(row)
                for column in PROJECT_TYPES:
                    for year in create_years(row[column]):
                        if first_line:
                            first_line = False
                        else:
                            out_file.write(b' ' * len(prefix))
                        out_file.write(TEMPLATE.format(
                            project_name=column,
                            project_year=year,
                            client_name=client_name(row)).encode())
        out_file.seek(-3, io.SEEK_CUR)
        out_file.write(b'])')
        out_file.truncate()
示例#4
0
OUT_PATH = '.\\user_seed.rb'
TEMPLATE = '\
{{school_id: {school_id!r}, \
role: {role!r}, \
first_name: {first_name!r}, \
last_name: {last_name!r}, \
email: {email!r}, \
phone: {phone!r}, \
box: {box!r}, \
major: {major!r}, \
minor: {minor!r}, \
classification: {classification!r}}},\r\n'

################################################################################

with security.open('Sales Managers Reps S13.csv', newline='') as file:
    reader = csv.DictReader(file)
    pivot = {field: [] for field in reader.fieldnames}
    for row in reader:
        for key, value in row.items():
            pivot[key].append(value)

MAJOR = set(filter(None, pivot['Major']))
MINOR = set(filter(None, pivot['Minor']))
CLASS = set(filter(None, pivot['Class']))

def generate_choice(iterable):
    array = tuple(iterable)
    while True:
        yield random.choice(array)