Ejemplo n.º 1
0
def main():
    apikey = fetchKey()
    accounts = []
    acc = Account("xdddd", "123456789", "BRONZE", "I", 65)
    accounts.append(acc)
    #accounts.append(Account("xdddd","123456789","BRONZE", "I", 65))
    acc.save()
    fetchAccounts()
Ejemplo n.º 2
0
def signup():
    info = request.json
    # check there is a username and password
    if info is None or 'username' not in info or 'password' not in info:
        return jsonify(status=400, result="Missing Fields")
    print(info)
    username = str(info['username'])
    password = str(info['password'])

    # make an account class with the hashed info
    salt = hash_utils.generate_salt()
    digest = hash_utils.hmac_hash(password, salt)
    account = Account(username=username,
                      hashed_password=digest,
                      salt=salt,
                      type="Student")

    # try to save the data
    # if the username is not unique, pymongo will tell us :D
    try:
        student = account.save()
        # Create a student profile
        profile = StudentProfile(student=student).save()
        return jsonify(status=200, result="OK")
    except ValidationError as e:
        print(e)
        return jsonify(status=400, result="Validation Error " + e)
    except NotUniqueError as e:
        print(e)
        return jsonify(status=400, resuls="Username already taken.")
Ejemplo n.º 3
0
def thread_import_student_data(lines):
    from scraper import highschool_exists
    index = ['username', 'password', 'state', 'high_school_name',
             'high_school_city', 'high_school_state', 'gpa', 'college_class',
             'major_1', 'major_2', 'sat_math', 'sat_ebrw', 'act_english',
             'act_math', 'act_reading', 'act_science', 'act_composite',
             'sat_lit', 'sat_us', 'sat_world', 'sat_math_1', 'sat_math_2',
             'sat_eco_bio', 'sat_mol_bio', 'sat_chem', 'sat_physics',
             'ap_passed']

    for line in lines:
        username = line[0]
        password = line[1]
        salt = hash_utils.generate_salt()
        digest = hash_utils.hmac_hash(password, salt)
        account = Account(username=username,
                          hashed_password=digest,
                          salt=salt, type="Student")
        try:
            account.save()
        except Exception as e:
            # print(e)
            print("There was an error importing student data: "+username)

    for line in lines:
        username = line[0]
        try:
            account = Account.objects.get(username=username, type="Student")
        except:
            print("Account could not be loaded: "+username)
            continue
        # Make student profile class
        # TODO: Decide on what attributes are optional
        # TODO: Add checks for if this data is not pressent?
        hs_name = line[index.index('high_school_name')].title().replace(".", "")
        hs_city = line[index.index('high_school_city')].title()
        hs_state = line[index.index('high_school_state')]
        if hs_name != '' and hs_city != '' and hs_state != '':
            highschool_exists(hs_name, hs_city, hs_state)
        p = StudentProfile(
            student=account,
            gpa=float(line[index.index('gpa')]),
            residence_state=line[index.index('state')],
            high_school_name=hs_name,
            high_school_city=hs_city,
            high_school_state=hs_state,
            college_class=int(line[index.index('college_class')]))
        for x in range(index.index('major_1'), len(index)):
            info = index[x]
            data = line[x]
            if data != '':  # the field isn't empty
                if info == "major_1":
                    p.major_1 = data
                elif info == "major_2":
                    p.major_2 = data
                else:
                    p.grades[info] = int(data)
        try:
            p.save()
        except Exception as e:
            print(e)
            print("Profile couldn't be loaded: "+username)
            continue