def home(): if 'user' not in session: return redirect(url_for('index')) tweets = [] for each_id in pool_ids: tweet = redis.hgetall(each_id) new_tweet = handler.create_tweet(tweet, each_id) if "img" in tweet: new_tweet["img"] = s3.s3_retrieve(tweet["img"]) tweets.insert(0, new_tweet) current_user = session['id'].encode('utf-8') following = redis.smembers("f" + user_id_follow) googleid = session['user'] session_id = session['id'] username = redis.hget('users_id', session_id).decode('utf-8') return render_template('home.html', tweets=tweets, googleid=googleid, session_id=session_id, username=username)
def original_retweet(tweet_id): page = tweet_id[:4] tweet_id = tweet_id[4:] if tweet_id not in pool_ids: flash("The tweet does not exit.") if (page == "home"): return redirect(url_for('home')) elif (page == "feed"): return redirect(url_for('feed', user_id=session['id'])) return redirect(url_for('profile', session_id=session['id'])) tweet = redis.hgetall(str(tweet_id)) if "img" in tweet: tweet["img"] = s3.s3_retrieve(tweet["img"]) session_id = session['id'] tweet['hashtag_text'] = tweet['hashtag_text'].decode('utf-8') tweet['left_text'] = tweet['left_text'].decode('utf-8') tweet['right_text'] = tweet['right_text'].decode('utf-8') username = redis.hget('users_id', tweet['session_id']).decode('utf-8') current_user = redis.hget('users_id', session_id).decode('utf-8') return render_template('original_retweet.html', tweet=tweet, session_id=session_id, username=username, current_user=current_user)
def feed(user_id): try: valid_user = redis.hget('users_id', user_id).decode('utf-8') except AttributeError: flash("Invalid URL") return redirect(url_for('home')) current_user = session['id'].encode('utf-8') following = redis.smembers("b" + current_user) id_list = [] for each in following: id_list.append(each) tweets = [] for each_id in pool_ids: tweet = redis.hgetall(each_id) if tweet['session_id'] in id_list or tweet[ 'session_id'] == current_user: new_tweet = handler.create_tweet(tweet, each_id) if "img" in tweet: new_tweet["img"] = s3.s3_retrieve(tweet["img"]) tweets.insert(0, new_tweet) session_id = session['id'] username = redis.hget('users_id', session_id).decode('utf-8') return render_template('feed.html', tweets=tweets, session_id=user_id, username=username)
def profile(session_id): session_id = session_id.encode('utf-8') tweets = [] for each_id in pool_ids: tweet = redis.hgetall(each_id) if tweet['session_id'] == session_id: new_tweet = handler.create_tweet(tweet, each_id) if "img" in tweet: new_tweet["img"] = s3.s3_retrieve(tweet["img"]) tweets.insert(0, new_tweet) current_user = session['id'].encode('utf-8') following = redis.smembers("b" + current_user) following_names = [] following_names_id = {} for each in following: name = redis.hget('users_id', each) following_names.append(name) following_names_id[name] = each follower = redis.smembers("f" + session_id) follow_names = [] follow_names_id = {} for each in follower: name = redis.hget('users_id', each) follow_names.append(name) follow_names_id[name] = each try: username = redis.hget('users_id', session_id).decode('utf-8') except AttributeError: flash("Invalid URL") return redirect(url_for("home")) avatar = redis.hget('avatars_id', session_id) viewing_user = session['id'] user = redis.hget('users_id', viewing_user).decode('utf-8') return render_template( 'profile.html', id=session['id'], #id of the user seeing the page session_id=session_id, username=username, user=user, tweets=tweets, avatar=avatar, follower=follower, follow_names=follow_names, follow_names_id=follow_names_id, following_names=following_names, following_names_id=following_names_id)
def hashtag(tweet_id): hash_tweet = redis.hgetall(str(tweet_id)) tweets = [] for each_id in pool_ids: tweet = redis.hgetall(each_id) if hash_tweet['hashtag_text'] in tweet['hashtag_text']: new_tweet = handler.create_tweet(tweet, each_id) if "img" in tweet: new_tweet["img"] = s3.s3_retrieve(tweet["img"]) tweets.insert(0, new_tweet) session_id = session['id'] username = redis.hget('users_id', session_id).decode('utf-8') return render_template('hashtag.html', tweets=tweets, hashtag=hash_tweet['hashtag_text'].decode('utf-8'), session_id=session['id'], username=username, tweet_id=tweet_id)