-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource.py
67 lines (64 loc) · 1.93 KB
/
source.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
60
61
62
63
64
65
66
67
import json
import codecs
from gensim.models import LdaModel
from gensim.corpora import Dictionary
from gensim import corpora, models
import tomotopy as tp
# file = open("D:/final_result.json", 'r', encoding='utf-8')
# line = file.readline()
file_record = open("D:/records.json", 'r', encoding='utf-8')
line = file_record.readline()
source_all = []
number = 0
while line:
number = number + 1
dic = json.loads(line)
print(number)
source_all.append(dic["source"])
line = file_record.readline()
source = set(source_all)
for element in source:
file = open("D:/records.json", 'r', encoding='utf-8')
line = file.readline()
publish_time_all = []
number = 0
while line:
number = number + 1
dic = json.loads(line)
source = dic["source"]
print(number)
if source == element:
print("找到")
publish_time_all.append(dic["publish_time"])
line = file.readline()
time = sorted(set(publish_time_all))
numbers = []
for time_stap in time:
number_new = 0
for time_all in publish_time_all:
if time_all == time_stap:
number_new = number_new + 1
numbers.append(number_new)
final_result = list(zip(time, numbers))
title_file_name = r"D:/source/" + element + ".txt"
ms = open(title_file_name, 'w', encoding='utf-8')
for key in final_result:
ms.write(str(key))
ms.write('\n')
print('写入完成')
file.close()
# numbers = []
# for source_single in source:
# number_new = 0
# for single_source in source_all:
# if single_source == source_single:
# number_new = number_new+1
# numbers.append(number_new)
# final_result = list(zip(source, numbers))
# title_file_name = 'D:/source.txt'
# ms = open(title_file_name, 'w', encoding='utf-8')
# for element in final_result:
# ms.write(str(element))
# ms.write('\n')
# print('写入完成')
# file.close()