-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuspendedChecker.py
More file actions
79 lines (55 loc) · 1.96 KB
/
SuspendedChecker.py
File metadata and controls
79 lines (55 loc) · 1.96 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import re
import json
import praw
import pprint
from requests import Session
path = "~/Reddit_MDA/"
#path = "/Users/gusta/Desktop/Python/Codes reddit/"
# Creates empty lists for the authors
fullauthors = []
authors = []
# Potential code for looping over all files
# for filename in os.listdir(folder_path):
# if os.path.splitext(filename)[1] == ".json":
# with open(os.path.join(path, filename), "r", errors="replace") as data:
#author = json.loads(line.strip())["author"]
#fullauthors.append(author)
with open('sample_data/json/RC_2015-02.json', 'r') as obj:
data = obj.read()
# Appends the author names to a list
result = re.findall(r"""author"(:".+?")""", data)
fullauthors.append(result)
# List collapsing
for sublist in fullauthors:
for item in sublist:
authors.append(item)
# Removes additional characters
cleanedlist1 = [sub.replace(':', '') for sub in authors]
cleanedlist2 = [sub.replace('"', '') for sub in cleanedlist1]
# Initiates praw session
session = Session()
session.verify = "/path/to/certfile.pem"
reddit = praw.Reddit(client_id="Qhw6nE9tDBhPCw",
client_secret="h_Drz8nU5f0yVupjz5bYHm0U0_8",
user_agent="testscript by /u/independ8",)
print(reddit.user.me())
print(reddit.read_only)
# Creates empty blacklist
blacklist = []
#redditor = reddit.redditor(cleanedlist2[10])
user_list = [reddit.redditor(x) for x in cleanedlist2 if x != "[deleted]"]
for redditor in user_list:
try:
if hasattr(redditor, 'fullname'):
print(redditor, "alive")
elif hasattr(redditor, 'is_suspended'):
blacklist.append(redditor)
print(redditor, "blacklist")
else:
print("ERROR", redditor)
except:
print(redditor)
# Writes list items into a new txt.file
with open ('Blacklist2005-12.txt', 'w') as filehandle:
for item in blacklist:
filehandle.write('%s\n' % item)