From 7edd569090ad7fdc312eb82f1a78eb4e6c981850 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 16 Aug 2022 18:53:24 +0200 Subject: [PATCH] refactor nitter --- files/classes/comment.py | 7 +++++-- files/helpers/regex.py | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/files/classes/comment.py b/files/classes/comment.py index 1f002e883..3a804f051 100644 --- a/files/classes/comment.py +++ b/files/classes/comment.py @@ -21,8 +21,11 @@ def normalize_urls_runtime(body, v): if v and v.reddit != 'old.reddit.com': body = reddit_to_vreddit_regex.sub(rf'\1https://{v.reddit}/\2/', body) - if v.nitter: body = twitter_to_nitter_regex.sub(r'https://nitter.42l.fr/\1', body) - if v.imginn: body = body.replace('https://instagram.com/', 'https://imginn.com/') + if v.nitter: + body = body.replace('https://twitter.com/', 'https://nitter.42l.fr/') + body = body.replace('https://nitter.42l.fr/i/', 'https://twitter.com/i/') + if v.imginn: + body = body.replace('https://instagram.com/', 'https://imginn.com/') return body diff --git a/files/helpers/regex.py b/files/helpers/regex.py index 108ae0cf1..90849a231 100644 --- a/files/helpers/regex.py +++ b/files/helpers/regex.py @@ -90,8 +90,6 @@ greentext_regex = re.compile("(\n|^)>([^ >][^\n]*)", flags=re.A) ascii_only_regex = re.compile("[ -~]+", flags=re.A) -twitter_to_nitter_regex = re.compile("https:\/\/twitter.com\/(\w{2,15}(\/status\/\d+[^/]*)?)", flags=re.A) - reddit_to_vreddit_regex = re.compile('(^|>|")https:\/\/old.reddit.com\/(r|u)\/', flags=re.A) reddit_domain_regex = re.compile("(^|\s|\()https?:\/\/(reddit\.com|new\.reddit.com|www\.reddit.com|i\.reddit\.com|libredd\.it|teddit\.net)\/(r|u)\/", flags=re.A)