Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import date, timedelta
- from getpass import getpass
- import os
- import praw
- def fix_sticky(reddit, subreddit_name):
- title_prefix = "Daily General Discussion "
- for submission in reddit.subreddit(subreddit_name).stream.submissions():
- # check if the post is by automod
- if submission.author.name == "AutoModerator"
- # check if post is today's daily discussion
- if submission.title == f"{title_prefix}{date.today().strftime('%B %d, %Y')}":
- if submission.stickied:
- # we do nothing, everything is as it should be.
- print(f'Sticky did not need fixing at {datetime.now()}')
- return False
- # check if old daily discussion is still stickied
- top_sticky = reddit.get_sticky(subreddit_name, bottom=False)
- yesterday = date.today() - timedelta(1)
- if top_sticky.title == f"{title_prefix}{yesterday.strftime('%B %d, %Y')}":
- raise ValueError('Top sticky invalid, check title prefix and date.')
- # unsticky old daily discussion.
- top_sticky.mod.sticky(state=False, top=True)
- # sticky old daily discussion.
- submission.mod.sticky(state=True, top=True)
- print(f'Fixed sticky at {datetime.now()}')
- return True
- if __name__ == "__main__":
- user = input('Username:')
- password = getpass('Password:')
- reddit = praw.Reddit(client_id=os.getenv('CLIENT_ID'),
- client_secret=os.getenv('CLIENT_SECRET'),
- user_agent='Autosticky Fix',
- username=username,
- password=password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement