From 78a419ac0ef7b9311d43d9aa37a92015c5f7ea53 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 7 Feb 2022 13:54:19 +0200 Subject: [PATCH] gf --- files/helpers/const.py | 11 ++++++++++- files/routes/posts.py | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/files/helpers/const.py b/files/helpers/const.py index ed39da738..453fb6020 100644 --- a/files/helpers/const.py +++ b/files/helpers/const.py @@ -588,4 +588,13 @@ ROLES={ } if SITE_NAME == 'Drama': patron = 'Paypig' -else: patron = 'Patron' \ No newline at end of file +else: patron = 'Patron' + +REDDIT_NOTIFS = { + 'idio3': IDIO_ID, + 'aevann': AEVANN_ID, + 'carpflo': CARP_ID, + 'carpathianflorist': CARP_ID, + 'carpathian florist': CARP_ID, + 'the_homocracy': HOMO_ID +} \ No newline at end of file diff --git a/files/routes/posts.py b/files/routes/posts.py index be0e9845d..6ed595e0a 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -720,9 +720,11 @@ def thumbnail_thread(pid): if SITE == 'rdrama.net': for t in ("submission","comment"): - for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=rdrama&size=1').json()["data"]: + word = random.choice(('rdrama','marsey')) - body_html = sanitize(f'New rdrama mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) + for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={word}&size=1').json()["data"]: + + body_html = sanitize(f'New {word} mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).first() @@ -744,7 +746,8 @@ def thumbnail_thread(pid): notif = Notification(comment_id=new_comment.id, user_id=admin.id) db.add(notif) - for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=aevann&size=1').json()["data"]: + k,val = random.choice(REDDIT_NOTIFS.items()) + for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q={k}&size=1').json()["data"]: try: body_html = sanitize(f'New mention of you: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) except: continue existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html).first() @@ -760,10 +763,36 @@ def thumbnail_thread(pid): db.add(new_comment) db.flush() - notif = Notification(comment_id=new_comment.id, user_id=AEVANN_ID) + notif = Notification(comment_id=new_comment.id, user_id=val) db.add(notif) + if SITE == 'pcmemes.net': + for t in ("submission","comment"): + for i in requests.get(f'https://api.pushshift.io/reddit/{t}/search?html_decode=true&q=pcmemes.net&size=1').json()["data"]: + + body_html = sanitize(f'New pcmemes.net mention: https://old.reddit.com{i["permalink"]}?context=89', noimages=True) + + existing_comment = db.query(Comment.id).filter_by(author_id=NOTIFICATIONS_ID, parent_submission=None, distinguish_level=6, body_html=body_html, level=1, sentto=0).first() + + if existing_comment: break + + print(body_html, flush=True) + new_comment = Comment(author_id=NOTIFICATIONS_ID, + parent_submission=None, + distinguish_level=6, + body_html=body_html, + level=1, + sentto=0, + ) + db.add(new_comment) + db.flush() + + admins = db.query(User).filter(User.admin_level > 2).all() + for admin in admins: + notif = Notification(comment_id=new_comment.id, user_id=admin.id) + db.add(notif) + db.commit() db.close() stdout.flush()