forked from woct0rdho/pkuholebackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
batchcheckcomment.py
50 lines (39 loc) · 1.35 KB
/
batchcheckcomment.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
#!/usr/bin/python3
import os
from utils import get_comment, read_posts, write_posts
default_reply = -1
fix_comment = True
cdname = os.path.dirname(__file__)
archive_dir = os.path.join(cdname, 'archive')
def check_comment(filename):
post_list = read_posts(filename)
updated = False
for post in post_list:
comment_list = []
cid_set = set()
for comment in post['comments']:
if comment['cid'] in cid_set:
print(post['pid'], comment['cid'])
updated = True
else:
comment_list.append(comment)
cid_set.add(comment['cid'])
post['comments'] = comment_list
if default_reply is not False and (
post['reply'] != default_reply
and post['reply'] != len(post['comments'])):
print(post['pid'], 'replies not match', post['reply'],
len(post['comments']))
if fix_comment:
get_comment(post)
updated = True
if updated:
write_posts(filename, post_list)
if __name__ == '__main__':
for root, dirs, files in os.walk(archive_dir):
for file in sorted(files):
if file < 'pkuhole201507':
continue
print(file)
filename = os.path.join(root, file)
check_comment(filename)