From 5abca18d0406e25506347d57d9549c75e6478e35 Mon Sep 17 00:00:00 2001 From: Socks Date: Thu, 5 Apr 2018 03:20:19 +0100 Subject: [PATCH] /tag/test to find posts with #test --- Tweeder.py | 10 ++++++++++ backend/timeline.py | 8 ++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Tweeder.py b/Tweeder.py index 206dac9..b7cbe56 100644 --- a/Tweeder.py +++ b/Tweeder.py @@ -323,6 +323,16 @@ def messaging(user): return redirect(request.referrer) +@app.route('/tag/', methods=['GET']) +def findtag(tagname): + logged_in = session['username'] if ('username' in session.keys()) else False + return render_template('timeline.html', + title=str("#" + tagname), + logged_in=logged_in, + posts=timeline.find_posts_by_hashtag(tagname), + theme=accounts.get_theme(logged_in)) + + @app.route('/pin/', methods=['GET']) def pin(post_id): if timeline.get_poster(post_id).lower() == session['username'].lower(): diff --git a/backend/timeline.py b/backend/timeline.py index 364dffb..1de6dcf 100644 --- a/backend/timeline.py +++ b/backend/timeline.py @@ -8,7 +8,7 @@ timeline_db = db.statuses def post_status(username, content, private=False, replyTo=False, location=False): - if not content: # Don't let people post blank posts + if not content: # Don't let people post blank posts return currentTimeDate = datetime.datetime.now() @@ -29,7 +29,7 @@ def post_status(username, content, private=False, replyTo=False, location=False) 'reposts': [], 'replies': [], 'replyTo': ObjectId(replyTo) if replyTo else False, - 'hashtags': [x for x in content.split() if x.startswith("#")], + 'hashtags': [x[1:] for x in content.split() if x.startswith("#")], 'mentions': accounts_mentioned, 'location': False or location, 'private': False or private, @@ -114,5 +114,9 @@ def get_mentions(username): return timeline_db.find({"mentions": username.lower()}).sort('timePosted', pymongo.DESCENDING) +def find_posts_by_hashtag(tag): + return timeline_db.find({'hashtags': tag}) + + def post_details(post_id): return timeline_db.find_one({'_id': ObjectId(post_id)}) \ No newline at end of file