Ejemplo n.º 1
0
    def post(self):
        user = users.get_current_user()  #User Login Information for Database

        if not user:
            self.render_template(
                "permissiondenied.html",
                params={"login_url": users.create_login_url('/')})
            return

        recname = self.request.get("name")  #Restaurant Name
        recstreet = self.request.get("street")  #Restaurant Street
        recplz = self.request.get("plz")  # Restaurant Zip Code
        recplace = self.request.get("ort")  #Restaurant Place
        recfrom = self.request.get("from")  #Restaurant Tip from
        recuserself = self.request.get("user")  #User Name
        recprice = int(self.request.get("price"))  #Price Ranking
        reckitchen = self.request.get("kueche")  #what kind of kitchen

        recom = Recommendation(user=user.nickname(),
                               name=recname,
                               street=recstreet,
                               plz=recplz,
                               place=recplace,
                               by=recfrom,
                               user_self=recuserself,
                               price=recprice,
                               kitchen=reckitchen)
        recom.put()
        return self.redirect_to("rec-list")
Ejemplo n.º 2
0
    def post(self, recoms_id):
        user = users.get_current_user()

        if not user:
            self.render_template(
                "permissiondenied.html",
                params={"login_url": users.create_login_url('/')})
            return

        rename = self.request.get("name")  # name of the Restaurant
        restreet = self.request.get("street")  # street of the Restaurant
        replz = self.request.get("plz")  # post code of the Restaurant
        replace = self.request.get("ort")  # town/city of the Restaurant
        reinfo = self.request.get("info")  # Note Text of the Restaurant
        revisit = self.request.get("visit")  # Visit time of the Restaurant
        price = int(self.request.get("price"))  # Price Info of the Restaurant
        rating = int(
            self.request.get("rating"))  # Self Rating of the Restaurant
        rekitchen = self.request.get(
            "kueche")  # what for kitchen gives in the Restaurant

        lokal = Gastro(user=user.nickname(),
                       name=rename,
                       street=restreet,
                       plz=replz,
                       place=replace,
                       note=reinfo,
                       time=revisit,
                       kitchen=rekitchen,
                       rating=rating,
                       price=price)
        lokal.put()
        recoms = Recommendation.get_by_id(int(recoms_id))
        recoms.key.delete()
        return self.redirect_to("rest-list")
Ejemplo n.º 3
0
def save_recommendation(rec_info):

    rec = Recommendation(rec_info=rec_info,
                         rec_date=datetime.now().timestamp(),
                         user_email=user_email)

    db.session.add(rec)
    db.session.commit()

    return rec
Ejemplo n.º 4
0
def add_recs_to_recommendations_table(recs_dataframe, user_id):
    """Add recommendations to database.
    Not standalone; called within create_and_save_recommendations."""

    recs_created = 0
    for i, row in recs_dataframe.iterrows():
        current_userbook = UserBook.query.filter(UserBook.book_id == row['book_id'],
                            UserBook.user_id == user_id).first()
        new_recommendation = Recommendation(date_created = datetime.now(),
                                userbook_id = current_userbook.userbook_id)
        db.session.add(new_recommendation)
        recs_created += 1
    db.session.commit()

    return recs_created
Ejemplo n.º 5
0
    def get(self, recoms_id):
        recoms = Recommendation.get_by_id(int(recoms_id))
        q = urllib.urlencode({
            "query":
            (recoms.name + " in " + recoms.place).encode(encoding='ascii',
                                                         errors='ignore'),
            "key":
            "AIzaSyBKdIPR1Q6TzIvjJuJzIyvybo6Mg1JLm64"
        })

        url = "https://maps.googleapis.com/maps/api/place/textsearch/json?" + q
        result = urlfetch.fetch(url)

        restaurant_info = json.loads(result.content)

        params = {"recoms": recoms, "restaurant_info": restaurant_info}
        return self.render_template("recom_details.html", params=params)
Ejemplo n.º 6
0
def upload_file():
    """Saves and Processes Submitted Image"""

    # get the user's image and saves it to an upload folder
    f = request.files['userimage']

    filename = secure_filename(f.filename)
    file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
    f.save(file_path)

    # crop the image to the user's face using the crop_face function
    cropped_face = crop_face(app.config['UPLOAD_FOLDER'], filename)

    # if there are no/too many faces detected in our image, flash error and have the user resumbit an image
    if cropped_face is None:
        os.remove(file_path)
        return "No Image Found"

    else:
        #use the get_hex function to get a hex code for the cropped face image
        face_hex_code = get_hex(20, cropped_face)
        foundation_matches = get_top_foundations(face_hex_code)

    user = User.query.get(session["user_id"])
    time_submitted = datetime.datetime.utcnow()

    # add image obj to db
    image_obj = UserImage(hex_code=face_hex_code,
                          user_id=user.user_id,
                          time_stamp=time_submitted,
                          image_location=file_path)

    db.session.add(image_obj)
    db.session.commit()

    #  add recommendation object to db
    for lst in foundation_matches:
        for item in lst:
            recommendation = Recommendation(image_id=image_obj.image_id,
                                            user_id=user.user_id,
                                            sku_id=item.sku_id)
            db.session.add(recommendation)
    db.session.commit()

    return "Processed Image"
Ejemplo n.º 7
0
def add_recommendations_to_userbooks_table(recs_dataframe, user_id):
    """When book recommendations are generated, add to SQLAlchemy."""

    for i, row in recs_dataframe.iterrows():
        new_userbook = UserBook(user_id=user_id,
            source = "nextbook-rec",
            status = "rec_no_response",
            book_id= row['book_id'])
        db.session.add(new_userbook)
    db.session.flush()

    for i, row in recs_dataframe.iterrows():
        current_userbook = UserBook.query.filter(UserBook.book_id==row['book_id'],
            UserBook.user_id==user_id).first()
        new_recommendation = Recommendation(date_created=datetime.now(),
            userbook_id=current_userbook.userbook_id)
        db.session.add(new_recommendation)

    db.session.commit()
    return None
Ejemplo n.º 8
0
def add_rec_to_db():
    """recordes info submitted by user, creates the objects for the db, and adds to the db"""

    #Update session on login - get the username in the session
    username = session['username']

    #then get that user's user object,
    user_obj = User.query.filter_by(username=username).first()

    #then get the user id to pass into the rec table
    user_id = user_obj.user_id


    #get the city_name & info separately since we need city_name for a query
    city_name = request.form.get('city_name')
    city_name = city_name.lower()
    city_info = request.form.get('city_info')


    #create the city obj if it doesn't exist other wise get the city_id for recs instantiation.
    city_obj = City.query.filter_by(city_name=city_name).first()
        
    if city_obj == None:
        city = City(city_name=city_name, city_info=city_info)
        db.session.add(city)
        db.session.commit()
        city_id = city.city_id
    else:    
        city_id = city_obj.city_id

    #get the path for four images, save it in the directory and then save the path before adding to the db in url variable
    file = request.files['file']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url = f'static/images/{filename}'

    file = request.files['file2']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url2 = f'static/images/{filename}'

    file = request.files['file3']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url3 = f'static/images/{filename}'

    file = request.files['file4']
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        app.logger.info(os.path.join(app.config['UPLOAD_FOLDER']))
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        img_url4 = f'static/images/{filename}'



    #add to the database
    recommendation = Recommendation(rec_name = request.form.get('rec_name'), stay_name= request.form.get('stay_name'), 
                stay_info = request.form.get('stay_info'), eat_name= request.form.get('eat_name'), 
                eat_info = request.form.get('eat_info'), do_name= request.form.get('do_name'), 
                do_info = request.form.get('do_info'), user_id=user_id, city_id=city_id, img_url=img_url, img_url2=img_url2, img_url3=img_url3, img_url4=img_url4)

    #call the save function to add to the database
    db.session.add(recommendation)
    db.session.commit()

    flash("Awesome! You've created a recommendation")
    return redirect(f'/view_recommendation/{recommendation.rec_id}')
Ejemplo n.º 9
0
def example_data():
    UserImage.query.delete()
    Favorite.query.delete()
    Review.query.delete()
    Brand.query.delete()
    Foundation.query.delete()
    Recommendation.query.delete()
    User.query.delete()

    new_user = User(fname="Bobby",
                    lname="Bob",
                    email="*****@*****.**",
                    create_date=datetime.datetime.utcnow(),
                    birthday="1991-01-12 00:00:00")
    new_user.set_password("1234")
    db.session.add(new_user)
    db.session.commit()

    new_image = UserImage(
        hex_code="#BA977D",
        user_id=1,
        time_stamp=datetime.datetime.utcnow(),
        image_location=
        "/home/vagrant/src/Foundation_Project/static/uploads/girl-glowing-skin-blue-eyes.jpg"
    )
    db.session.add(new_image)
    db.session.commit()

    new_brand = Brand(
        product_id="P87985432",
        brand_name="FENTY BEAUTY by Rihanna",
        display_name="Pro Filt'r Soft Matte Longwear Foundation",
        target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432",
        rating=4.09740000000000038)
    db.session.add(new_brand)
    db.session.commit()

    new_brand_2 = Brand(
        product_id="P400888",
        brand_name="Black Up",
        display_name="Matifying Fluid Foundation",
        target_url="www.sephora.com/product/matifying-fluid-foundation-P400888",
        rating=4.2727)
    db.session.add(new_brand_2)
    db.session.commit()

    new_brand_3 = Brand(
        product_id="P432234",
        brand_name="Lawless",
        display_name="Woke Up Like This Flawless Finish Foundation",
        target_url=
        "www.sephora.com/product/woke-up-like-this-flawless-finish-foundation-P432234",
        rating=3.9836)
    db.session.add(new_brand_3)
    db.session.commit()

    new_brand_4 = Brand(
        product_id="P427301",
        brand_name="NARS",
        display_name="Natural Radiant Longwear Foundation",
        target_url=
        "www.sephora.com/product/natural-radiant-longwear-foundation-P427301",
        rating=3.6461)

    db.session.add(new_brand_4)
    db.session.commit()

    new_foundation = Foundation(
        sku_id=1925148,
        product_id="P87985432",
        foundation_hex_code="#F6D4C4",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925148",
        shade_image_url="www.sephora.com/productimages/sku/s1925148+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925148-main-Lhero.jpg")
    db.session.add(new_foundation)
    db.session.commit()

    new_foundation_2 = Foundation(
        sku_id=1925155,
        product_id="P87985432",
        foundation_hex_code="#F4D6B9",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925155",
        shade_image_url="www.sephora.com/productimages/sku/s1925155+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925155-main-Lhero.jpg")
    db.session.add(new_foundation_2)
    db.session.commit()

    new_foundation_3 = Foundation(
        sku_id=1925163,
        product_id="P87985432",
        foundation_hex_code="#EFD1B3",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925163",
        shade_image_url="www.sephora.com/productimages/sku/s1925163+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925163-main-Lhero.jpg")

    db.session.add(new_foundation_3)
    db.session.commit()

    new_foundation_4 = Foundation(
        sku_id=1925171,
        product_id="P87985432",
        foundation_hex_code="#E8D2BB",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925171",
        shade_image_url="www.sephora.com/productimages/sku/s1925171+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925171-main-Lhero.jpg")
    db.session.add(new_foundation_4)
    db.session.commit()

    new_foundation_5 = Foundation(
        sku_id=1925189,
        product_id="P87985432",
        foundation_hex_code="#F2CCB2",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925189",
        shade_image_url="www.sephora.com/productimages/sku/s1925189+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925189-main-Lhero.jpg")
    db.session.add(new_foundation_5)
    db.session.commit()

    new_foundation_6 = Foundation(
        sku_id=1925197,
        product_id="P87985432",
        foundation_hex_code="#EDC8B4",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925197",
        shade_image_url="www.sephora.com/productimages/sku/s1925197+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925197-main-Lhero.jpg")
    db.session.add(new_foundation_6)
    db.session.commit()

    new_foundation_7 = Foundation(
        sku_id=11925205,
        product_id="P87985432",
        foundation_hex_code="#EECDB1",
        foundation_target_url=
        "www.sephora.com/product/pro-filtr-soft-matte-longwear-foundation-P87985432?skuId=1925205",
        shade_image_url="www.sephora.com/productimages/sku/s1925205+sw.jpg",
        hero_image_url=
        "https://www.sephora.com/productimages/sku/s1925205-main-Lhero.jpg")
    db.session.add(new_foundation_7)
    db.session.commit()

    new_review = Review(user_id=1,
                        product_id="P87985432",
                        review_content="best brand ever ever")
    db.session.add(new_review)
    db.session.commit()

    new_recommendation = Recommendation(image_id=1, sku_id=1925148, user_id=1)
    db.session.add(new_recommendation)
    db.session.commit()

    new_recommendation_2 = Recommendation(image_id=1,
                                          sku_id=1925155,
                                          user_id=1)
    db.session.add(new_recommendation_2)
    db.session.commit()

    new_recommendation_3 = Recommendation(image_id=1,
                                          sku_id=1925163,
                                          user_id=1)
    db.session.add(new_recommendation_3)
    db.session.commit()

    new_recommendation_4 = Recommendation(image_id=1,
                                          sku_id=1925171,
                                          user_id=1)
    db.session.add(new_recommendation_4)
    db.session.commit()

    new_recommendation_5 = Recommendation(image_id=1,
                                          sku_id=1925189,
                                          user_id=1)
    db.session.add(new_recommendation_5)
    db.session.commit()

    new_recommendation_6 = Recommendation(image_id=1,
                                          sku_id=1925197,
                                          user_id=1)
    db.session.add(new_recommendation_6)
    db.session.commit()

    new_favorite = Favorite(sku_id=1925148, user_id=1)
    db.session.add(new_favorite)
    db.session.commit()
# This is basically the heart of my flask

from flask import Flask, render_template, request, redirect, url_for, jsonify
import pickle
from model import Recommendation

recommend = Recommendation()
app = Flask(__name__)  # intitialize the flaks app  # common


@app.route('https://capstonespm123.herokuapp.com/', methods=['POST', 'GET'])
def home():
    flag = False
    data = ""
    if request.method == 'POST':
        flag = True
        user = request.form["userid"]
        data = recommend.getTopProducts(user)
    return render_template('index.html', data=data, flag=flag)


if __name__ == '__main__':
    app.run(debug=True
            )  # this command will enable the run of your flask app or api

    #,host="0.0.0.0")
Ejemplo n.º 11
0
 def get(self, recoms_id):
     recoms = Recommendation.get_by_id(int(recoms_id))
     params = {"recoms": recoms}
     return self.render_template("recom_push.html", params=params)
Ejemplo n.º 12
0
 def get(self):
     recoms = Recommendation.query().fetch()
     params = {"recoms": recoms}
     return self.render_template("recommendation.html", params=params)