-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetusers.py
59 lines (47 loc) · 1.34 KB
/
getusers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
"""
Created on 8 August 2017
@author: Rishabh Patil
"""
import praw
import sys
import operator
import json
with open("config.json","r") as f:
config = json.load(f)
reddit = praw.Reddit(client_id='',
client_secret='',
user_agent='',
username='',
password='')
print(reddit.user.me())
subreddit = reddit.subreddit('mbti')
print(subreddit.display_name)
print(subreddit.title)
with open("authors.json","r") as f:
authors=json.load(f)
def add_author(name,text_flair,css_flair):
global authors
if name not in authors:
authors[name] = (text_flair,css_flair)
count = 0
for submission in subreddit.submissions():
count+=1
sys.stdout.write("\r{0} {1}".format(count,len(authors)))
sys.stdout.flush()
fail = 1
while fail:
try:
submission.comments.replace_more(limit=None)
add_author(str(submission.author),submission.author_flair_text,submission.author_flair_css_class)
for comment in submission.comments.list():
add_author(str(comment.author),comment.author_flair_text,comment.author_flair_css_class)
fail = 0
except:
continue
with open("authors.json",'w+') as f:
# print(authors)
json.dump(authors,f,indent=4)
# config["timelast"] = timelast + (timestep*steps)
# with open("config.json",'w') as f:
# json.dump(config,f)