-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape_user.py
33 lines (26 loc) · 982 Bytes
/
scrape_user.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
import praw
import yaml
import json
params = yaml.safe_load(open('params.yaml'))['scrape_user']
username = params['username']
reddit = praw.Reddit(
client_id="83adArc_D-RzLA",
client_secret="sYyJyc67NIeGvOu5Aenq-nVr3hZbrw",
password="rosjia@3",
user_agent="testscript by u/fakebot3",
username="hushjeee",
)
def query_comments_of_user(username, how_deep=50):
redditor = reddit.redditor(username)
dictionary_of_subreddits = {}
comments = redditor.comments.new(limit=how_deep)
for comment in comments:
try:
dictionary_of_subreddits[comment.subreddit.display_name] += 1
except KeyError:
dictionary_of_subreddits[comment.subreddit.display_name] = 1
with (open("target/user.json", "w+")) as outfile:
json.dump(dictionary_of_subreddits, outfile, indent=4)
return dictionary_of_subreddits
if __name__ == "__main__":
print(query_comments_of_user(username))