Ejemplo n.º 1
0
def import_typeform(filename):
    import csv

    fields = ["id"] + typeform.FIELDS + [
        "start_time", "submit_time", "network_id"
    ]
    vals = []
    with open(filename, newline='') as csvfile:
        reader = csv.DictReader(csvfile, fields)
        for row in reader:
            row["first_hack"] = row["first_hack"] == "1"
            row["sponsor"] = row["sponsor"] == "1"
            row["swag"] = row["swag"] == "1"
            row["code_of_conduct"] = row["code_of_conduct"] == "1"
            row["terms_and_conditions"] = row["terms_and_conditions"] == "1"
            vals.append(row)

        create_tables()
        with db.database.atomic():
            (Registration.insert_many(vals[1:]).on_conflict(
                "update",
                conflict_target=[Registration.id],
                preserve=Registration.hacker_discord).execute())
        click.echo("Uploaded {0} entries to the Registration table".format(
            len(vals) - 1))