-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathapp.py
57 lines (46 loc) · 2.84 KB
/
app.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
# -*- coding: utf-8 -*-
import os
import codecs
from extract.ZengJianChiExtractor import ZengJianChiExtractor
def extract_zengjianchi(zjc_ex, html_dir_path, html_id):
record_list = []
print(html_id + ' is processing')
for record in zjc_ex.extract(os.path.join(html_dir_path, html_id), html_id):
if record is not None and record.shareholderFullName is not None and \
len(record.shareholderFullName) > 1 and \
record.finishDate is not None and len(record.finishDate) >= 6:
tmp_result = record.to_result()
if tmp_result is not None:
record_list.append("%s,%s" % (html_id.split('.')[0], tmp_result))
for record in record_list:
print(record)
return record_list
def extract_zengjianchi_from_html_dir(zjc_ex, html_dir_path, res_path):
with codecs.open(res_path, 'w', encoding='utf-8') as f:
f.write("公告id,股东全称,股东简称,变动截止日期,变动价格,变动数量,变动后持股数,变动后持股比例\n")
print("公告id,股东全称,股东简称,变动截止日期,变动价格,变动数量,变动后持股数,变动后持股比例\n")
for html_id in os.listdir(html_dir_path):
record_list = extract_zengjianchi(zjc_ex, html_dir_path, html_id)
for record in record_list:
f.write(record + "\n")
if __name__ == "__main__":
# 提取单个 html 中的记录
'''
zengjianchi_config_file_path = 'config/ZengJianChiConfig.json'
ner_model_dir_path = 'E:/WorkBench/Courses/Big-Data/Proj2-Finance/ltp_data_v3.4.0'
ner_blacklist_file_path = 'config/ner_com_blacklist.txt'
zjc_ex = ZengJianChiExtractor(zengjianchi_config_file_path, ner_model_dir_path, ner_blacklist_file_path)
print('html文件,股东全称,股东简称,变动截止日期,变动价格,变动数量,变动后持股数,变动后持股比例')
extract_zengjianchi(zjc_ex, '../train_data/增减持/html', '6927.html')
'''
# 提取所有 html 中的记录
zengjianchi_config_file_path = 'config/ZengJianChiConfig.json'
# ner_model_dir_path = 'E:/WorkBench/Courses/Big-Data/Proj2-Finance/ltp_data_v3.4.0'
# ner_model_dir_path = '/home/swj/Tools/ltp_data_v3.4.0'
ner_model_dir_path = 'D:/pyltp/ltp_data'
ner_blacklist_file_path = 'config/ner_com_blacklist.txt'
public_time_path = '../train_public_time/增减持公告时间_train.csv'
zjc_ex = ZengJianChiExtractor(zengjianchi_config_file_path, ner_model_dir_path, ner_blacklist_file_path, public_time_path)
# extract_zengjianchi_from_html_dir(zjc_ex, '../train_data/增减持/html', './results/HodingChange.csv')
# extract_zengjianchi_from_html_dir(zjc_ex, '../data/train_data/增减持/html', './results/HodingChange.csv')
extract_zengjianchi_from_html_dir(zjc_ex, '../zengjianchi/html', './results/ZengJianChi.csv')