setting up events

This commit is contained in:
lza_menace 2021-04-29 20:55:34 -07:00
parent ce735058fb
commit 133057b4e9
3 changed files with 29 additions and 3 deletions

View file

@ -2,6 +2,9 @@ setup:
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
shell:
./bin/cmd shell
dev:
./bin/dev

View file

@ -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)

View file

@ -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]