-
Notifications
You must be signed in to change notification settings - Fork 3
/
8k_parser_test.py
53 lines (45 loc) · 1.73 KB
/
8k_parser_test.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
import re
import sys
from bs4 import BeautifulSoup
import tqdm
sys.path.append('src')
import EDGAR as edgar
import EDGAR.html as html
from EDGAR.subheader_parser_8k import Parser_8K
DATA_DIR = '8kdata'
tikrs = ['aapl', 'msft', 'amzn', 'tsla', 'googl', 'goog', 'unh', 'jnj', 'cvx',
'jpm', 'hd', 'v', 'pg']
metadata = edgar.Metadata(data_dir=DATA_DIR)
kparser = Parser_8K()
dataloader = edgar.DataLoader(tikrs=tikrs, document_type='8-K',
data_dir=DATA_DIR)
count_multi = 0
tikrs, submission,files, sections, texts, max_occurrence = [],[],[],[],[],[]
for idx, text in enumerate(dataloader):
text_sec ,list_section = kparser.get_sections(text, True)
filename = dataloader.files[idx]
#submission, tikr are not easily available
sub = dataloader.sub_lookup[filename]
tikr = dataloader.tikr_lookup[sub]
if(len(text_sec) == 0 ):
print(tikr, sub ,filename, 'no section')
continue
max_occur = 0
# check max occurrence of the specified section
for i, s in enumerate(list_section):
curr_occur = kparser.get_num_occurrence(text, s)
tikrs += [tikr]
submission += [sub]
files += [filename]
sections += [s]
texts += [text_sec[i]]
max_occurrence += [curr_occur]
if curr_occur > max_occur:
max_occur = curr_occur
if max_occur > 1:
count_multi += 1
print('number of files:',len(dataloader))
print("there are ", count_multi, "files has section name occur more than 1 time.")
with open("file.txt","w") as f:
for (tikr, sub,file, section, t, occur) in zip(tikrs, submission,files, sections, texts, max_occurrence):
f.write("{0},{1},{2},{3},{4},{5}\n".format(tikr, sub,file, section, t, occur))