Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # original written by u/3dsf with many improvements and troubleshooting from u/dnandrea
- # currently does not address automod flairs, as automod does create a link_flair_template_id attribute (u/dnandrea)
- import praw
- reddit = praw.Reddit('flairUP', user_agent='flairUP v.1a')
- #or if your not set up with a praw.ini file use below.
- # (these are not my credentials)
- #reddit = praw.Reddit(client_id='SI8pN3DSbt0zor',
- # client_secret='xaxkj7HNh8kwg8e5t4m6KvSrbTI',
- # password='1guiwevlfo00esyy',
- # user_agent='flairIT by /u/3dsf',
- # username='3dsf')
- sub = 'dsf'
- #########################################################################
- #########################################################################
- #Poll Reddit by sub
- subReddit = reddit.subreddit(sub)
- # returns link templates on specified subreddit
- flair_template = subReddit.flair.link_templates
- flair_list = [flair['id'] for flair in flair_template]
- flair_list_text = [flair['text'] for flair in flair_template]
- print ('\n\n*' + '{:^78}'.format('****** STARTing flairUP ******') + '*\n\n')
- print(flair_list_text)
- print(flair_list)
- #Go through the results
- for submission in subReddit.search('flair:"dsf"', sort='new', limit=999):
- print(submission.title)
- #Checks if flair attribute exists, sets None if doesn't and assigns to temp var
- ##AutoMod Flairs have no link flair template id attribute
- linkFlairTemplateID = getattr(submission, 'link_flair_template_id', None)
- #Checks post flair template id against sub flair template id list
- if linkFlairTemplateID not in flair_list:
- print('-------- negative flair template match')
- else:
- print(linkFlairTemplateID)
- submission.flair.select(linkFlairTemplateID)
- print ('\n\n' + '{:^80}'.format('******* FINISHED *******') + '\n\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement