fix controversial sorting setting for comments
This commit is contained in:
parent
6170645576
commit
23653c1354
2 changed files with 17 additions and 14 deletions
|
@ -1,3 +1,5 @@
|
|||
import re
|
||||
from urllib.parse import urlencode, urlparse, parse_qs
|
||||
from flask import *
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.orm import relationship, deferred
|
||||
|
@ -247,6 +249,18 @@ class Comment(Base, Age_times, Scores, Stndrd, Fuzzing):
|
|||
if not v or v.slurreplacer: body = body.replace(" nigger"," 🏀").replace(" Nigger"," 🏀").replace(" NIGGER"," 🏀").replace(" pedo"," libertarian").replace(" Pedo"," Libertarian ").replace(" PEDO"," LIBERTARIAN ").replace(" tranny"," 🚄").replace(" Tranny"," 🚄").replace(" TRANNY"," 🚄").replace(" fag"," cute twink").replace(" Fag"," Cute twink").replace(" FAG"," CUTE TWINK").replace(" faggot"," cute twink").replace(" Faggot"," Cute twink").replace(" FAGGOT"," CUTE TWINK").replace(" trump"," DDR").replace(" Trump"," DDR").replace(" TRUMP"," DDR").replace(" biden"," DDD").replace(" Biden"," DDD").replace(" BIDEN"," DDD").replace(" steve akins"," penny verity oaken").replace(" Steve Akins"," Penny Verity Oaken").replace(" STEVE AKINS"," PENNY VERITY OAKEN").replace(" RETARD"," RSLUR").replace(" rapist"," male feminist").replace(" Rapist"," Male feminist").replace(" RAPIST"," MALE FEMINIST").replace(" RETARD"," RSLUR").replace(" rapist"," male feminist").replace(" Rapist"," Male feminist").replace(" RAPIST"," MALE FEMINIST").replace(" RETARD"," RSLUR").replace(" rapist"," male feminist").replace(" Rapist"," Male feminist").replace(" RAPIST"," MALE FEMINIST").replace(" kill yourself"," keep yourself safe").replace(" KILL YOURSELF"," KEEP YOURSELF SAFE").replace(" trannie"," 🚄").replace(" Trannie"," 🚄").replace(" TRANNIE"," 🚄").replace(" troon"," 🚄").replace(" Troon"," 🚄").replace(" TROON"," 🚄")
|
||||
if v and not v.oldreddit: body = body.replace("old.reddit.com", "reddit.com")
|
||||
|
||||
if v.controversial:
|
||||
for i in re.finditer('(/comments/.*?)"', body):
|
||||
url = i.group(1)
|
||||
p = urlparse(url).query
|
||||
p = parse_qs(p)
|
||||
|
||||
if 'sort' not in p:
|
||||
p['sort'] = ['controversial']
|
||||
|
||||
url_noquery = url.split('?')[0]
|
||||
body = body.replace(url, f"{url_noquery}?{urlencode(p, True)}")
|
||||
|
||||
return body
|
||||
|
||||
@property
|
||||
|
@ -309,4 +323,4 @@ class Notification(Base):
|
|||
|
||||
def __repr__(self):
|
||||
|
||||
return f"<Notification(id={self.id})>"
|
||||
return f"<Notification(id={self.id})>"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import bleach
|
||||
from bs4 import BeautifulSoup
|
||||
from bleach.linkifier import LinkifyFilter
|
||||
from urllib.parse import ParseResult, urlunparse, urlencode, urlparse, parse_qs
|
||||
from urllib.parse import ParseResult, urlunparse, urlparse
|
||||
from functools import partial
|
||||
from .get import *
|
||||
from os import path
|
||||
|
@ -204,18 +204,7 @@ def sanitize(text, linkgen=False):
|
|||
for rd in ["https://reddit.com/", "https://new.reddit.com/", "https://www.reddit.com/", "https://redd.it/"]:
|
||||
sanitized = sanitized.replace(rd, "https://old.reddit.com/")
|
||||
|
||||
for i in re.finditer('(/comments/.*?)"', sanitized):
|
||||
url = i.group(1)
|
||||
p = urlparse(url).query
|
||||
p = parse_qs(p)
|
||||
|
||||
if 'sort' not in p:
|
||||
p['sort'] = ['controversial']
|
||||
|
||||
url_noquery = url.split('?')[0]
|
||||
sanitized = sanitized.replace(url, f"{url_noquery}?{urlencode(p, True)}")
|
||||
|
||||
for i in re.finditer('<p>(https://.*)</p>', sanitized):
|
||||
sanitized = sanitized.replace(i.group(1), f"<a href={i.group(1)} target='_blank'>{i.group(1)}</p>")
|
||||
|
||||
return sanitized
|
||||
return sanitized
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue