예제 #1
0
def main(args):
    # Read source
    if args.source_type == "excel":
        df = pd.read_excel(open(args.source,'rb'), sheet_name=args.sheet_name, encoding='utf-8')
    else:
        df = pd.read_csv(args.source)

    UserDB.connect(args.db_path)
    UserDB.initSchema()
    # Iterate data
    users = []
    for row in df.values:
        firstname = row[3]
        lastname = row[4]
        teamName = None
        distance = row[8]
        if "10 KM" not in distance:
            # Skip 5K runner
            continue

        first10k_word = row[10]
        if first10k_word == "เคย":
            first10k = 0
        elif first10k_word == "ไม่เคย":
            first10k = 1
        else:
            assert(0)
            
        user = (firstname, lastname, teamName, first10k)
        users.append(user)
    print("Inserting %d users" % (len(users)))
    UserDB.insertUsers(users)
    UserDB.close()
예제 #2
0
def testDB(users, teams, request):
    if os.path.exists(DEFAULT_TEST_DB):
        print("Clean old test database.")
        os.remove(DEFAULT_TEST_DB)
    UserDB.connect(DEFAULT_TEST_DB)
    UserDB.initSchema()

    for team in teams.values():
        UserDB.insertTeam(team["teamName"])

    user_values = []
    for user in users.values():
        user_values.append([user["firstname"], user["lastname"], user["teamId"], user["first10k"]])
    UserDB.insertUsers(user_values)

    def testDB_teardown():
        # Teardown is called when a method using testDB ends.
        UserDB.close()
    request.addfinalizer(testDB_teardown)