fdsfs
This commit is contained in:
parent
d98c81196d
commit
8b9b2697d0
1 changed files with 66 additions and 50 deletions
|
@ -11,44 +11,59 @@ from flask import *
|
||||||
from files.__main__ import app, limiter, db_session
|
from files.__main__ import app, limiter, db_session
|
||||||
from pusher_push_notifications import PushNotifications
|
from pusher_push_notifications import PushNotifications
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
import gevent
|
||||||
|
|
||||||
site = environ.get("DOMAIN").strip()
|
site = environ.get("DOMAIN").strip()
|
||||||
|
|
||||||
if PUSHER_ID: beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
if PUSHER_ID: beams_client = PushNotifications(instance_id=PUSHER_ID, secret_key=PUSHER_KEY)
|
||||||
|
|
||||||
db = db_session()
|
def leaderboard_thread():
|
||||||
|
global users1
|
||||||
|
global users2
|
||||||
|
global users3
|
||||||
|
global users4
|
||||||
|
global users5
|
||||||
|
global users6
|
||||||
|
global users7
|
||||||
|
global userss9
|
||||||
|
global users10
|
||||||
|
global userss12
|
||||||
|
global userss13
|
||||||
|
global userss15
|
||||||
|
|
||||||
users = db.query(User)
|
db = db_session()
|
||||||
|
|
||||||
users1 = users.order_by(User.coins.desc()).limit(25).all()
|
users = db.query(User)
|
||||||
users2 = users.order_by(User.stored_subscriber_count.desc()).limit(25).all()
|
|
||||||
users3 = users.order_by(User.post_count.desc()).limit(25).all()
|
|
||||||
users4 = users.order_by(User.comment_count.desc()).limit(25).all()
|
|
||||||
users5 = users.order_by(User.received_award_count.desc()).limit(25).all()
|
|
||||||
if SITE == 'pcmemes.net': users6 = users.order_by(User.basedcount.desc()).limit(25).all()
|
|
||||||
else: users6 = None
|
|
||||||
users7 = users.order_by(User.coins_spent.desc()).limit(25).all()
|
|
||||||
|
|
||||||
votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all()
|
users1 = users.order_by(User.coins.desc()).limit(25).all()
|
||||||
votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all()
|
users2 = users.order_by(User.stored_subscriber_count.desc()).limit(25).all()
|
||||||
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
|
users3 = users.order_by(User.post_count.desc()).limit(25).all()
|
||||||
users8 = db.query(User).filter(User.id.in_(votes3.keys())).all()
|
users4 = users.order_by(User.comment_count.desc()).limit(25).all()
|
||||||
users9 = []
|
users5 = users.order_by(User.received_award_count.desc()).limit(25).all()
|
||||||
for user in users8: users9.append((user, votes3[user.id]))
|
if SITE == 'pcmemes.net': users6 = users.order_by(User.basedcount.desc()).limit(25).all()
|
||||||
users9 = sorted(users9, key=lambda x: x[1], reverse=True)
|
else: users6 = None
|
||||||
userss9 = users9[:25]
|
users7 = users.order_by(User.coins_spent.desc()).limit(25).all()
|
||||||
|
|
||||||
users10 = users.order_by(User.truecoins.desc()).limit(25).all()
|
votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote, Vote.submission_id==Submission.id).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all()
|
||||||
|
votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote, CommentVote.comment_id==Comment.id).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all()
|
||||||
|
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
|
||||||
|
users8 = db.query(User).filter(User.id.in_(votes3.keys())).all()
|
||||||
|
users9 = []
|
||||||
|
for user in users8: users9.append((user, votes3[user.id]))
|
||||||
|
users9 = sorted(users9, key=lambda x: x[1], reverse=True)
|
||||||
|
userss9 = users9[:25]
|
||||||
|
|
||||||
badges = db.query(Badge.user_id, func.count(Badge.user_id)).group_by(Badge.user_id).order_by(func.count(Badge.user_id).desc()).all()
|
users10 = users.order_by(User.truecoins.desc()).limit(25).all()
|
||||||
badges = dict(badges)
|
|
||||||
users11 = db.query(User).filter(User.id.in_(badges.keys())).all()
|
|
||||||
users12 = []
|
|
||||||
for user in users11: users12.append((user, badges[user.id]))
|
|
||||||
users12 = sorted(users12, key=lambda x: x[1], reverse=True)[:25]
|
|
||||||
userss12 = users12[:25]
|
|
||||||
|
|
||||||
if site == 'rdrama.net':
|
badges = db.query(Badge.user_id, func.count(Badge.user_id)).group_by(Badge.user_id).order_by(func.count(Badge.user_id).desc()).all()
|
||||||
|
badges = dict(badges)
|
||||||
|
users11 = db.query(User).filter(User.id.in_(badges.keys())).all()
|
||||||
|
users12 = []
|
||||||
|
for user in users11: users12.append((user, badges[user.id]))
|
||||||
|
users12 = sorted(users12, key=lambda x: x[1], reverse=True)[:25]
|
||||||
|
userss12 = users12[:25]
|
||||||
|
|
||||||
|
if site == 'rdrama.net':
|
||||||
topmakers = {}
|
topmakers = {}
|
||||||
for k, val in marseys.items():
|
for k, val in marseys.items():
|
||||||
if val in topmakers: topmakers[val] += 1
|
if val in topmakers: topmakers[val] += 1
|
||||||
|
@ -62,20 +77,21 @@ if site == 'rdrama.net':
|
||||||
topmakers = sorted(topmakers3, key=lambda x: x[1], reverse=True)[:25]
|
topmakers = sorted(topmakers3, key=lambda x: x[1], reverse=True)[:25]
|
||||||
users13 = topmakers
|
users13 = topmakers
|
||||||
userss13 = users13[:25]
|
userss13 = users13[:25]
|
||||||
else: userss13 = None
|
else: userss13 = None
|
||||||
|
|
||||||
votes1 = db.query(Vote.user_id, func.count(Vote.user_id)).filter(Vote.vote_type==1).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
|
votes1 = db.query(Vote.user_id, func.count(Vote.user_id)).filter(Vote.vote_type==1).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
|
||||||
votes2 = db.query(CommentVote.user_id, func.count(CommentVote.user_id)).filter(CommentVote.vote_type==1).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
|
votes2 = db.query(CommentVote.user_id, func.count(CommentVote.user_id)).filter(CommentVote.vote_type==1).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
|
||||||
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
|
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
|
||||||
users14 = db.query(User).filter(User.id.in_(votes3.keys())).all()
|
users14 = db.query(User).filter(User.id.in_(votes3.keys())).all()
|
||||||
users15 = []
|
users15 = []
|
||||||
for user in users14:
|
for user in users14:
|
||||||
users15.append((user, votes3[user.id]-user.post_count-user.comment_count))
|
users15.append((user, votes3[user.id]-user.post_count-user.comment_count))
|
||||||
users15 = sorted(users15, key=lambda x: x[1], reverse=True)[:25]
|
users15 = sorted(users15, key=lambda x: x[1], reverse=True)[:25]
|
||||||
userss15 = users15[:25]
|
userss15 = users15[:25]
|
||||||
|
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
gevent.spawn(leaderboard_thread())
|
||||||
@app.get("/grassed")
|
@app.get("/grassed")
|
||||||
@auth_required
|
@auth_required
|
||||||
def grassed(v):
|
def grassed(v):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue