-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount_num.py
31 lines (24 loc) · 937 Bytes
/
count_num.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
def count(path):
with open(path, encoding='utf-8') as f:
weibo_num = 0
retweet_num = 0
comment_num = 0
up_num = 0
line = f.readlines()
#先看用户信息
#然后再看微博内容
for content in line:
if content.startswith('评论数:'):
temp = int(content.split(':')[1])
comment_num += temp
if content.startswith('点赞数:'):
temp = int(content.split(':')[1])
up_num += temp
if content.startswith('转发数:'):
temp = int(content.split(':')[1])
retweet_num += temp
weibo_num += 1
return [weibo_num, comment_num, up_num, retweet_num]
if __name__ =='__main__':
path = 'textData/2020 0201 0210.txt'
weibo_num, comment_num, up_num, retweet_num = count(path)