-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patha8_2 xbrl to text.py
168 lines (127 loc) · 4.15 KB
/
a8_2 xbrl to text.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#%%
from datetime import datetime,timedelta
import sys,os,copy,ast,socket,random,math,webbrowser,getpass,time,shutil
import numpy as np
import pandas as pd
from pytz import timezone
import matplotlib.pyplot as plt
#%%
from datetime import datetime,timedelta
import sys,os,copy,ast,socket,random,math,webbrowser,getpass,time,shutil
import numpy as np
import pandas as pd
from pytz import timezone
import matplotlib.pyplot as plt
from pathlib import Path
from sec_edgar_downloader import Downloader
import re
import openai,getpass,os
from openai import OpenAI
path1=f'{path_to_openai_api}'
with open(path1,'r') as f:
key=f.readline()
os.environ["OPENAI_API_KEY"] = key
openai.api_key = key
openai_client = OpenAI(
# defaults to os.environ.get("OPENAI_API_KEY")
api_key=key,
)
from twilio.rest import Client
import yagmail
from datetime import datetime,timedelta
import pandas as pd
# Your Account SID from twilio.com/console
account_sid = "{account_sid_twilio}"
auth_token = "{auth_token_twilio}"
client = Client(account_sid, auth_token)
sender='{id_yagmail}'
#receiver='[email protected]'
email1=sender
passw1='{password_yagmail}'
passw1='{password_yagmail}'
yag = yagmail.SMTP(user=sender,password=passw1)
content1='1'
subject1='1'
def send_email(to_email,title,content):
yag.send(to=to_email,subject=title,contents=content)
def gpt_answer(define,content):
response = openai_client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": define},
{"role": "user", "content": content}
]
)
return response.choices[0].message.content
# %%
# %%
#%%
dl = Downloader("eontech", "[email protected]")
dl
tickers='CTAS,TT,RSG,CAH,FICO,TW,MANH,FCN,PSN,OBDC,CWCO'
ticker_list = [ticker.strip() for ticker in tickers.split(',')]
ticker='BRBR'
for ticker in ticker_list:
print("ticker: ",ticker,'generate 10k...')
dl.get("10-K", ticker, limit=1)
time.sleep(1)
# dl.get("10-K", 'TW', limit=1)
#%%
path1=f'/Users/{getpass.getuser()}/Library/CloudStorage/[email protected]/My Drive/t1_code/t6_trading_news/sec-edgar-filings/full-submission.txt'
with open(path1,'r') as file:
data=file.read()
TARGET_NAME='ITEM 1'.lower()
#%%
cleaned_text = re.sub('<[^>]+>', '', data)
cleaned_text
# %%
len(cleaned_text)
# %%
with open("data/temp.txt",'a+') as file:
file.write(cleaned_text)
# %%
path1=f'/Users/{getpass.getuser()}/Library/CloudStorage/[email protected]/My Drive/t1_code/t6_trading_news/sec-edgar-filings/TW/10-K/0001758730-23-000047/full-submission.txt'
with open(path1,'r') as file:
data=file.read()
TARGET_NAME='ITEM 1. business'.lower()
# TARGET_NAME='ITEM 7.'
split_list=data.lower().split(TARGET_NAME)
split_list
#%%
len(split_list)
#%%
if len(split_list)>3:
splited_list=data.lower().split(TARGET_NAME)[1].split('\n')[:20]
else:
splited_list=data.lower().split(TARGET_NAME)[-1].split('\n')[:20]
print("\n>> len(splited_list)= ", len(splited_list))
text1="".join(splited_list)
cleaned_text = re.sub('<[^>]+>', '', text1)[:4000]
cleaned_text
#%%
print("\n>> len(cleaned_text)= ", len(cleaned_text))
define="summarize based which products/services this company make. why is it better than competitors. what kind of customers will buy and why"
answer1=gpt_answer(define,cleaned_text)
answer1
TARGET_NAME='ITEM 7. mana'.lower()
split_list=data.lower().split(TARGET_NAME)
if len(split_list)>3:
splited_list=data.lower().split(TARGET_NAME)[2].split('\n')[:20]
else:
splited_list=data.lower().split(TARGET_NAME)[-1].split('\n')[:20]
text1="".join(splited_list)
cleaned_text = re.sub('<[^>]+>', '', text1)[:4000]
cleaned_text
define="summarize based on what are important events that happened for the company. If it has any financial numbers or other numbers, give me summary with the numbers."
answer2=gpt_answer(define,cleaned_text)
answer2
# %%
cleaned_text
#%%
path1=f'{path_to_openai_api}'
path1=f'/Users/{getpass.getuser()}/Library/CloudStorage/[email protected]/My Drive/t1_code/t6_trading_news/data/temp.txt'
with open(path1,'r') as f:
text1=f.read()
cleaned_text = re.sub('<[^>]+>', '', text1)[:4000]
cleaned_text
# %%