diff --git a/Makefile b/Makefile index 251224b..7fbe5b1 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ setup: python3 -m venv .venv .venv/bin/pip install -r requirements.txt +shell: + ./bin/cmd shell + dev: ./bin/dev diff --git a/suchwow/app.py b/suchwow/app.py index f987622..d79ce59 100644 --- a/suchwow/app.py +++ b/suchwow/app.py @@ -12,7 +12,7 @@ from suchwow import config from suchwow.models import Post, Profile, Comment, Notification, db, Moderator from suchwow.routes import auth, comment, post, profile, leaderboard, api from suchwow.utils.decorators import login_required, moderator_required -from suchwow.utils.helpers import post_webhook +from suchwow.utils.helpers import post_webhook, get_activity from suchwow.reddit import make_post from suchwow.discord import post_discord_webhook from suchwow import wownero, filters @@ -36,6 +36,11 @@ def index(): itp = 15 page = request.args.get("page", 1) submitter = request.args.get("submitter", None) + content = request.args.get("content", None) + if content == "trending": + posts = get_activity() + return render_template("index.html", posts=posts) + try: page = int(page) except: @@ -44,7 +49,7 @@ def index(): posts = Post.select().where(Post.approved==True).order_by(Post.timestamp.desc()) if submitter: - posts = posts.where(Post.submitter == submitter) + posts = posts.where(Post.submitter==submitter) paginated_posts = posts.paginate(page, itp) total_pages = ceil(posts.count() / itp) diff --git a/suchwow/utils/helpers.py b/suchwow/utils/helpers.py index a014d95..e247cd5 100644 --- a/suchwow/utils/helpers.py +++ b/suchwow/utils/helpers.py @@ -1,7 +1,8 @@ from requests import post as r_post from json import dumps from flask import session, current_app -from suchwow.models import Moderator +from suchwow.models import Moderator, Post +from suchwow.wownero import Wallet from suchwow import config @@ -36,3 +37,20 @@ def post_webhook(msg): return True except: return False + +def get_activity(): + posts = Post.select() + w = Wallet() + data = {} + for p in posts: + data[p.timestamp] = {'type': 'post', 'post': p} + for tx in w.incoming_transfers(p.account_index): + if 'timestamp' in tx: + data[tx['timestamp']] = {'type': 'tx', 'post': p} + + dates = sorted(data, reverse=True) + new_data = [] + for d in dates: + new_data.append(data[d]['post']) + + return new_data[0:20]