forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2021-11-26 22:11:39 +02:00
parent b1dee92e9d
commit a5ac491fea
10 changed files with 75 additions and 63 deletions

View File

@ -20,6 +20,7 @@ from urllib.parse import ParseResult, urlunparse, urlparse, quote
site = environ.get("DOMAIN").strip()
CATBOX_KEY = environ.get("CATBOX_KEY").strip()
titleheaders = {"User-Agent": f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"}
with open("snappy.txt", "r") as f: snappyquotes = f.read().split("{[para]}")
@ -391,17 +392,11 @@ def get_post_title(v):
url = request.values.get("url", None)
if not url: return abort(400)
headers = {"User-Agent": f"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.72 Safari/537.36"}
try: x = requests.get(url, headers=headers, timeout=5)
except BaseException: return {"error": "Could not reach page"}, 400
x = requests.get(url, headers=titleheaders, timeout=5)
if not x.status_code == 200: return {"error": f"Page returned {x.status_code}"}, x.status_code
soup = BeautifulSoup(x.content, 'html.parser')
return {"url": url, "title": soup.find('title').string}
try:
soup = BeautifulSoup(x.content, 'html.parser')
return {"url": url, "title": soup.find('title').string}
except BaseException:
return {"error": f"Could not find a title"}, 400
def archiveorg(url):
try: requests.get(f'https://web.archive.org/save/{url}', headers={'User-Agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}, timeout=100)

View File

@ -18,25 +18,6 @@ site = environ.get("DOMAIN").strip()
beams_client = PushNotifications(instance_id=PUSHER_INSTANCE_ID, secret_key=PUSHER_KEY)
@app.get("/most_downvoted")
@auth_desired
def most_downvoted(v):
votes = g.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()).limit(25).all()
votes2 = g.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()).limit(25).all()
votes = Counter(dict(votes)) + Counter(dict(votes2))
users = g.db.query(User).filter(User.id.in_(votes.keys())).all()
users2 = []
for user in users: users2.append((user, votes[user.id]))
users = sorted(users2, key=lambda x: x[1], reverse=True)[:25]
return render_template("most_downvoted.html", v=v, users=users)
@app.get("/@<username>/upvoters")
@auth_desired
def upvoters(v, username):
@ -267,10 +248,32 @@ def leaderboard(v):
users4 = users.order_by(User.comment_count.desc()).limit(10).all()
users5 = users.order_by(User.received_award_count.desc()).limit(10).all()
users7 = users.order_by(User.coins_spent.desc()).limit(20).all()
votes = g.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()).limit(25).all()
votes2 = g.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()).limit(25).all()
votes = Counter(dict(votes)) + Counter(dict(votes2))
users8 = g.db.query(User).filter(User.id.in_(votes.keys())).all()
users9 = []
for user in users8: users9.append((user, votes[user.id]))
users9 = sorted(users9, key=lambda x: x[1], reverse=True)[:25]
if 'pcmemes.net' in request.host:
users6 = users.order_by(User.basedcount.desc()).limit(10).all()
return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4, users5=users5, users6=users6, users7=users7)
return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4, users5=users5, users7=users7)
return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4, users5=users5, users6=users6, users7=users7, users9=users9)
return render_template("leaderboard.html", v=v, users1=users1, users2=users2, users3=users3, users4=users4, users5=users5, users7=users7, users9=users9)
@app.get("/@<username>/css")

View File

@ -10,7 +10,7 @@
</thead>
{% for user in users %}
<tr>
<td style="font-weight:bold;">{{users.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
</tr>
{% endfor %}

View File

@ -12,7 +12,7 @@
</thead>
{% for user in users %}
<tr>
<td style="font-weight:bold;">{{users.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold;">{% if user.ban_reason %}{{user.ban_reason}}{% endif %}</td>
<td style="font-weight:bold;" href="/@{{user.banned_by.username}}"><img loading="lazy" src="/uid/{{user.banned_by.id}}/pic" class="pp20"><span {% if user.banned_by.patron %}class="patron" style="background-color:#{{user.banned_by.namecolor}};"{% endif %}>{{user.banned_by.username}}</span></a></td>

View File

@ -16,7 +16,7 @@
</thead>
{% for user in users1 %}
<tr>
<td style="font-weight:bold;">{{users1.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.coins}}</td>
</tr>
@ -44,7 +44,7 @@
{% for user in users7 %}
<tr>
<td style="font-weight:bold;">{{users7.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold; fonts" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.coins_spent}}</td>
</tr>
@ -71,7 +71,7 @@
</thead>
{% for user in users2 %}
<tr>
<td style="font-weight:bold;">{{users2.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.stored_subscriber_count}}</td>
</tr>
@ -96,7 +96,7 @@
</thead>
{% for user in users3 %}
<tr>
<td style="font-weight:bold;">{{users3.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.post_count}}</td>
</tr>
@ -121,7 +121,7 @@
</thead>
{% for user in users4 %}
<tr>
<td style="font-weight:bold;">{{users4.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold; fonts" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.comment_count}}</td>
</tr>
@ -148,7 +148,7 @@
</thead>
{% for user in users5 %}
<tr>
<td style="font-weight:bold;">{{users5.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold; fonts" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.received_award_count}}</td>
</tr>
@ -156,6 +156,38 @@
</table>
<pre>
</pre>
<h5 style="font-weight:bold;text-align: center;">Most downvoted users</h5>
<pre>
</pre>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th style="font-weight: bold">#</th>
<th style="font-weight: bold">Name</th>
<th style="font-weight: bold">Downvotes</th>
</tr>
</thead>
<tbody id="followers-table">
{% for user in users9 %}
<tr>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user[0].namecolor}}; font-weight:bold;" href="/@{{user[0].username}}"><img loading="lazy" src="/uid/{{user[0].id}}/pic" class="pp20"><span {% if user[0].patron %}class="patron" style="background-color:#{{user[0].namecolor}};"{% endif %}>{{user[0].username}}</span></a></td>
<td style="font-weight: bold">{{user[1]}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% if "pcm" in request.host %}
<pre>
@ -176,7 +208,7 @@
</thead>
{% for user in users6 %}
<tr>
<td style="font-weight:bold;">{{users6.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold; fonts" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.basedcount}}</td>
</tr>

View File

@ -6,23 +6,5 @@
</pre>
<h5 style="text-align: center">Most downvoted users</h5>
<pre></pre>
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th style="font-weight: bold">#</th>
<th style="font-weight: bold">Name</th>
<th style="font-weight: bold">Downvotes</th>
</tr>
</thead>
<tbody id="followers-table">
{% for user in users %}
<tr>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user[0].namecolor}}; font-weight:bold;" href="/@{{user[0].username}}"><img loading="lazy" src="/uid/{{user[0].id}}/pic" class="pp20"><span {% if user[0].patron %}class="patron" style="background-color:#{{user[0].namecolor}};"{% endif %}>{{user[0].username}}</span></a></td>
<td style="font-weight: bold">{{user[1]}}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -12,7 +12,7 @@
</thead>
{% for user in users %}
<tr>
<td style="font-weight: bold">{{users.index(user)+1}}</td>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
</tr>
{% endfor %}

View File

@ -11,7 +11,7 @@
</thead>
{% for user in users %}
<tr>
<td style="font-weight:bold;">{{users.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold;">{{user.shadowbanned}}</td>
</tr>

View File

@ -12,7 +12,7 @@
</thead>
{% for user in successful %}
<tr>
<td style="font-weight: bold">{{successful.index(user)+1}}</td>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
</tr>
{% endfor %}
@ -30,7 +30,7 @@
</thead>
{% for user in failed2 %}
<tr>
<td style="font-weight: bold">{{failed2.index(user)+1}}</td>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
</tr>
{% endfor %}
@ -48,7 +48,7 @@
</thead>
{% for user in failed %}
<tr>
<td style="font-weight: bold">{{failed.index(user)+1}}</td>
<td style="font-weight: bold">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
</tr>
{% endfor %}

View File

@ -16,7 +16,7 @@
</thead>
{% for user in users %}
<tr>
<td style="font-weight:bold;">{{users.index(user)+1}}</td>
<td style="font-weight:bold;">{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}}; font-weight:bold;" href="/@{{user.username}}"><img loading="lazy" src="/uid/{{user.id}}/pic" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}};"{% endif %}>{{user.username}}</span></a></td>
<td style="font-weight:bold; text-align:right;">{{user.truecoins}}</td>
</tr>