Ejemplo n.º 1
0
def upload_file():
    """Allow user to upload photos"""

    file = request.files['file']
    caption = request.form['caption']
    hashtag = request.form['hashtag']

    user_id = session['user_id']

    if file.name == '':
        flash('No selected photos')
        return redirect(request.url)

    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        file_path = os.path.join(UPLOAD_FOLDER, filename)
        file.save(file_path)
        flash('Photo successfully uploaded')

        photo_user_id = session.get('user_id')

        new_photo = Photo(photo_user_id=photo_user_id,
                          photo_url=('/' + file_path),
                          caption=caption)

        db_hashtag = Hashtag.query.filter_by(hashtag=hashtag).first()

        if not db_hashtag:
            db_hashtag = Hashtag(hashtag=hashtag)

        new_photo.hashtags.append(db_hashtag)

        db.session.add(new_photo)
        db.session.commit()

        return redirect(f'/users/{user_id}')

    else:
        flash('Only png, jpg, jpeg, gif file types are allowed!')
        return redirect(request.url)
Ejemplo n.º 2
0
def load_user_moods(): 

    User_Moods.query.delete()
    
    user_mood_1= User_Moods(user_id=0, 
        mood_id=5, 
        datetime='2018-01-01 12:00:00',
        comments= "Feeling average...",
        hours_slept=8,
        exercise_mins=60)

    db.session.add(user_mood_1)
    db.session.commit()
    
    mood_pots = [1,2,3,4,5, 5,5, 5, 5, 6,6,6, 6,7,8,9,9,10,10,10,10,10]
    comments_pots = ["Feeling Average", "Positive Vibes", "Need Caffeine", "Sunny Day!", "Went for a walk", "Good times with friends", "Travel Fun", "Gloomy", "Too much caffeine", "Great Day", "Worked Overtime", "Cooked Dinner", "Beach Day", "PTO, Woo!", "Cranky today", ]
    hashtag_pots = [ "#Blessed", "#StillBlessed", "#RainyDay", "#BailedOnPlans", "#LegDay", "#WhenisFriYAY", "#Hungry" ,"#Bored", "#ItsHandled", "#TheStruggleIsReal", "#GoodTimes", "#WFH", "#Motivated", "#MoreSleepPlz", "#CoffeeBreaks", "#Glad2BeHere"]
    exercise_pots = [0,30,60,60,90,180,0,30]
    
    i = 1
    while i < 50:
        #never sad 
        #mood_id = random.randint(5,10)
        #high variation 
        #mood_pots = [1,1,1,2,2,2,3,4,6,7,8,9,9,10,10,10,10,10]
        #mood_id = random.choice(mood_pots)
        #mostly happy
        comments = random.choice(comments_pots)
        mood_id = random.choice(mood_pots)
        hours_slept = random.randint(0,2)+mood_id
        exercise_mins = random.choice(exercise_pots)
        month = 1+ int(i/27)
        day = i % 27 + 1
        
        # query for hashtag by text field
        # if it's NOT in the hashtag table, add it
        
       
        hashtag_text = random.choice(hashtag_pots)

        hashtag = Hashtag.query.filter(Hashtag.text == hashtag_text).first()
        if hashtag is None:
            hashtag = Hashtag(text=hashtag_text)
            db.session.add(hashtag)
            db.session.commit()

        user_mood_rnd = User_Moods(user_id=0, 
        mood_id=mood_id, 
        datetime='2018-' + str(month) +'-'+str(day) + ' 12:00:00',
        comments=comments,
        #comments= "Feeling average...",
        hours_slept= hours_slept,
        exercise_mins=exercise_mins)

        db.session.add(user_mood_rnd)
        db.session.commit()

        userdatahashtag = UserDataHashtags(hashtag_id=hashtag.hashtag_id, record_id=user_mood_rnd.record_id)
        
        db.session.add(userdatahashtag)
        db.session.commit()

        i+=1


# def load_user_hashtags():
#     Hashtag.query.delete()

#     i = 1 
#     while i < 50:
#         hashtag_pots = [ "#Blessed", "#StillBlessed", "#LegDay" "#WhenisFriYAY", "#Hungry" "#Bored", "#ItsHandled", "#TheStruggleIsReal", "#GoodTimes", "#WFH", "#Motivated", "#MoreSleepPlz" "#CoffeeBreaks", "#Glad2BeHere"]
#         hashtag_rnd = Hashtag(text=random.choice(hashtatg_pots))
#         db.session.add(hashtag_rnd)

#         db.session(commit)

#class Hashtag(db.Model):
    """ Table of all hashtags with an id, for searching later"""