SHOW:
|
|
- or go back to the newest paste.
1 | - | sub = '123' |
1 | + | #!/usr/bin/env python |
2 | # original written by u/3dsf with many improvements and troubleshooting from u/dnandrea | |
3 | # currently does not address automod flairs, as automod does create a link_flair_template_id attribute (u/dnandrea) | |
4 | ||
5 | import praw | |
6 | ||
7 | reddit = praw.Reddit('flairUP', user_agent='flairUP v.1a') | |
8 | #or if your not set up with a praw.ini file use below. | |
9 | # (these are not my credentials) | |
10 | #reddit = praw.Reddit(client_id='SI8pN3DSbt0zor', | |
11 | # client_secret='xaxkj7HNh8kwg8e5t4m6KvSrbTI', | |
12 | # password='1guiwevlfo00esyy', | |
13 | # user_agent='flairIT by /u/3dsf', | |
14 | # username='3dsf') | |
15 | ||
16 | sub = 'dsf' | |
17 | ||
18 | ######################################################################### | |
19 | - | #Iterate thru the results |
19 | + | |
20 | - | for submission in subReddit.search('flair:"321"', sort='new', limit=999): |
20 | + | |
21 | #Poll Reddit by sub | |
22 | subReddit = reddit.subreddit(sub) | |
23 | ||
24 | # returns link templates on specified subreddit | |
25 | flair_template = subReddit.flair.link_templates | |
26 | ||
27 | flair_list = [flair['id'] for flair in flair_template] | |
28 | flair_list_text = [flair['text'] for flair in flair_template] | |
29 | ||
30 | print ('\n\n*' + '{:^78}'.format('****** STARTing flairUP ******') + '*\n\n') | |
31 | print(flair_list_text) | |
32 | print(flair_list) | |
33 | ||
34 | #Go through the results | |
35 | for submission in subReddit.search('flair:"dsf"', sort='new', limit=999): | |
36 | print(submission.title) | |
37 | #Checks if flair attribute exists, sets None if doesn't and assigns to temp var | |
38 | ##AutoMod Flairs have no link flair template id attribute | |
39 | linkFlairTemplateID = getattr(submission, 'link_flair_template_id', None) | |
40 | #Checks post flair template id against sub flair template id list | |
41 | if linkFlairTemplateID not in flair_list: | |
42 | print('-------- negative flair template match') | |
43 | else: | |
44 | print(linkFlairTemplateID) | |
45 | submission.flair.select(linkFlairTemplateID) | |
46 | ||
47 | print ('\n\n' + '{:^80}'.format('******* FINISHED *******') + '\n\n') |