예제 #1
0
def addHome():
    with open("homes.csv", mode="r") as csv_file:
        csv_reader = csv.DictReader(csv_file)

        homesList = list()

        for row in csv_reader:
            newHome = Home()
            newHome.sell_price = row["Sell"]
            newHome.list_price = row[" \"List\""]
            newHome.living = row[" \"Living\""]
            newHome.rooms = row[" \"Rooms\""]
            newHome.beds = row[" \"Beds\""]
            newHome.bathrooms = row[" \"Baths\""]
            newHome.age = row[" \"Age\""]
            newHome.arces = row[" \"Acres\""]
            newHome.taxes = row[" \"Taxes\""]
            homesList.append(newHome)

        for home in homesList:
            db.session.add(home)

        if len(homesList) > 0:
            db.session.commit()

        return "Create homes successfully"
예제 #2
0
def seed_homes():

    homes = []

    with open("homes.csv", mode="r") as csv_file:
        csv_reader = csv.DictReader(csv_file)
        for row in csv_reader:

            home = Home()

            home.sell = row["Sell"].replace(" ", "")
            home.list = row[" \"List\""].replace(" ", "")
            home.living = row[" \"Living\""].replace(" ", "")
            home.rooms = row[" \"Rooms\""].replace(" ", "")
            home.beds = row[" \"Beds\""].replace(" ", "")
            home.baths = row[" \"Baths\""].replace(" ", "")
            home.age = row[" \"Age\""].replace(" ", "")
            home.acres = float(row[" \"Acres\""].replace(" ", ""))
            home.taxes = row[" \"Taxes\""].replace(" ", "")

            db.session.add(home)
            db.session.commit()

            homes.append(home)

    json_home = HomeSchema(many=True).dump(homes)

    return jsonify(json_home)
예제 #3
0
def seed():
    with open("homes.csv", mode="r") as csv_file:
        csv_reader = csv.DictReader(csv_file)
        for row in csv_reader:
            x = Home()
            x.sell = row["Sell"]
            x.list = row[' "List"']
            x.living = row[' "Living"']
            x.rooms = row[' "Rooms"']
            x.beds = row[' "Beds"']
            x.baths = row[' "Baths"']
            x.age = row[' "Age"']
            x.acres = row[' "Acres"']
            x.taxes = row[' "Taxes"']

            db.session.add(x)
        db.session.commit()

        homes = Home.query.all()
        json_homes = HomeSchema(many=True).dump(homes)
        return jsonify(json_homes)
예제 #4
0
def create_home():

    home = Home()

    sell = request.args.get('sell')
    list = request.args.get('list')
    living = request.args.get('living')
    rooms = request.args.get('rooms')
    beds = request.args.get('beds')
    baths = request.args.get('baths')
    age = request.args.get('age')
    acres = request.args.get('acres')
    taxes = request.args.get('taxes')

    if sell is not None:
        home.sell = sell
    else:
        home.sell = 0

    home.list = list

    if list is not None:
        home.list = list
    else:
        home.list = 0

    if living is not None:
        home.living = living
    else:
        home.living = 0

    if rooms is not None:
        home.rooms = rooms
    else:
        home.rooms = 0

    if beds is not None:
        home.beds = beds
    else:
        home.beds = 0

    if baths is not None:
        home.baths = baths
    else:
        home.baths = 0

    if age is not None:
        home.age = age
    else:
        home.age = 0

    if acres is not None:
        home.acres = acres
    else:
        home.acres = 0

    if taxes is not None:
        home.taxes = taxes
    else:
        home.taxes = 0

    db.session.add(home)
    db.session.commit()

    json_home = HomeSchema().dump(home)

    return jsonify(json_home)