Created
October 9, 2019 19:30
-
-
Save MrEdinLaw/97001c7b670b2459889806f39a2ee861 to your computer and use it in GitHub Desktop.
Widget updater for /r/bannerrequests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (C) 2020 Edin Demic @MrEdinLaw - All Rights Reserved | |
# You may use, and modify this code but not distribute | |
import praw | |
import re | |
from time import sleep | |
# REST API connection | |
reddit = praw.Reddit(client_id="", | |
client_secret="", | |
user_agent="", | |
username="", | |
password="") | |
while True: | |
subreddit = reddit.subreddit("") | |
syncedPosts = [] | |
summedUp = 0 | |
for submission in subreddit.new(limit=1000): | |
if submission.id not in syncedPosts: | |
if submission.link_flair_text == "Awaiting OP response" or submission.link_flair_text == "Completed request": | |
# print(submission.link_flair_text) | |
summedUp += 1 | |
syncedPosts.append(submission.id) | |
print(submission.url) | |
for submission in subreddit.hot(limit=1000): | |
if submission.id not in syncedPosts: | |
if submission.link_flair_text == "Awaiting OP response" or submission.link_flair_text == "Completed request": | |
#print(submission.link_flair_text) | |
summedUp += 1 | |
syncedPosts.append(submission.id) | |
print(submission.url) | |
widgets = subreddit.widgets | |
widgets._fetch() | |
match = False | |
for widget in widgets.sidebar: | |
if widget.shortName == "Banners made:": | |
textReplace = widget.text | |
match = re.search(rf"Total banners made so far:\s(\d+)", textReplace) | |
if match: | |
textReplace = textReplace.replace(match.group(0), match.group(0).replace(match.group(1),str(summedUp))) | |
widget = widget.mod.update(text=textReplace) | |
print("Widget Updated") | |
print("Going Again in 60Seconds") | |
sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment