QuantumLearner commited on
Commit
67169c8
·
verified ·
1 Parent(s): d7033ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -30
app.py CHANGED
@@ -6,10 +6,7 @@ import asyncio
6
  import aiohttp
7
  import os
8
 
9
- # Set wide layout
10
  st.set_page_config(layout="wide")
11
-
12
- # Global API key
13
  API_KEY = os.getenv("FMP_API_KEY")
14
 
15
  ########################################
@@ -57,7 +54,8 @@ async def fetch_8k_page(session, page, from_date, to_date, has_financial):
57
 
58
  async def fetch_all_8k(pages_to_fetch, from_date, to_date, has_financial):
59
  async with aiohttp.ClientSession() as session:
60
- tasks = [fetch_8k_page(session, p, from_date, to_date, has_financial) for p in range(pages_to_fetch)]
 
61
  results = []
62
  progress_bar = st.progress(0)
63
  completed = 0
@@ -88,7 +86,8 @@ async def fetch_company_page(session, symbol, filing_type, page):
88
 
89
  async def fetch_all_company(symbol, filing_type, pages_to_fetch):
90
  async with aiohttp.ClientSession() as session:
91
- tasks = [fetch_company_page(session, symbol, filing_type, p) for p in range(pages_to_fetch)]
 
92
  results = []
93
  progress_bar = st.progress(0)
94
  completed = 0
@@ -112,7 +111,11 @@ def live_feed_page():
112
  Use the filters to narrow down the list by filing type, date range, and whether the filing is complete.
113
  """
114
  )
115
-
 
 
 
 
116
  with st.sidebar:
117
  with st.expander("Live Feed Filter Parameters", expanded=True):
118
  filing_type = st.selectbox(
@@ -136,25 +139,30 @@ def live_feed_page():
136
  help="Check to show only filings marked as completed."
137
  )
138
  run_live = st.button("Run Live Feed Query")
139
-
140
- # Fixed backend parameter: limit is set to 500
141
- limit = 500
142
 
 
143
  if run_live:
144
- df = get_live_feed_data(limit, filing_type, from_date.isoformat(), to_date.isoformat(), is_done)
 
 
 
 
145
  st.write("### Live SEC Filings Data")
146
- st.dataframe(df, use_container_width=True)
147
 
148
  def eight_k_page():
149
  st.title("8-K Filings Specialized")
150
  st.write(
151
  """
152
  This page displays 8-K filings from public companies.
153
- 8-K filings are reports companies file when major events occur, like mergers, acquisitions, or leadership changes.
154
- Use the filter below to show only filings that include financial information if you prefer.
155
  """
156
  )
157
-
 
 
 
158
  with st.sidebar:
159
  with st.expander("8-K Filter Parameters", expanded=True):
160
  from_date = st.date_input(
@@ -174,29 +182,38 @@ def eight_k_page():
174
  )
175
  has_financial = has_financial_option.lower() == "true"
176
  run_8k = st.button("Run 8-K Query")
177
-
178
- pages_to_fetch = 15 # Fixed number of pages to iterate over
179
  if run_8k:
180
- # Run async requests to fetch 8-K pages concurrently and update a progress bar.
181
- results = asyncio.run(fetch_all_8k(pages_to_fetch, from_date.isoformat(), to_date.isoformat(), has_financial))
 
182
  dfs = [df for df in results if not df.empty]
183
  if dfs:
184
  df_all = pd.concat(dfs, ignore_index=True)
185
- st.write("### 8-K Filings Data")
186
- st.dataframe(df_all, use_container_width=True)
187
  else:
 
188
  st.warning("No data returned for the given parameters.")
189
 
 
 
 
 
190
  def company_specific_page():
191
  st.title("Company Specific SEC Filings")
192
  st.write(
193
  """
194
  This page displays filings for a specific company.
195
- SEC filings are official documents companies file with the government.
196
  Enter a company ticker (e.g., AAPL) and select a filing type (like 10-K or 10-Q) to view the reports.
197
  """
198
  )
199
-
 
 
 
 
 
200
  with st.sidebar:
201
  with st.expander("Company Filings Parameters", expanded=True):
202
  symbol = st.text_input(
@@ -210,22 +227,28 @@ def company_specific_page():
210
  help="Select the type of filing to retrieve."
211
  )
212
  run_company = st.button("Run Company Query")
213
-
214
- pages_to_fetch = 10 # Fixed number of pages to iterate over
215
 
 
216
  if run_company:
217
  if symbol.strip():
218
- results = asyncio.run(fetch_all_company(symbol.upper(), filing_type, pages_to_fetch))
 
 
219
  dfs = [df for df in results if not df.empty]
220
  if dfs:
221
  df_all = pd.concat(dfs, ignore_index=True)
222
- st.write(f"### SEC Filings for {symbol.upper()}")
223
- st.dataframe(df_all, use_container_width=True)
224
  else:
 
225
  st.warning("No filings found for the given parameters.")
226
  else:
227
  st.warning("Please enter a valid company ticker.")
228
 
 
 
 
 
229
  ########################################
230
  # MAIN APPLICATION
231
  ########################################
@@ -237,7 +260,7 @@ def main():
237
  ("Live Feed", "8-K Specialized", "Company Specific"),
238
  help="Navigate to the desired SEC filings page."
239
  )
240
-
241
  if page_selection == "Live Feed":
242
  live_feed_page()
243
  elif page_selection == "8-K Specialized":
@@ -248,11 +271,10 @@ def main():
248
  if __name__ == "__main__":
249
  main()
250
 
251
-
252
  hide_streamlit_style = """
253
  <style>
254
  #MainMenu {visibility: hidden;}
255
  footer {visibility: hidden;}
256
  </style>
257
  """
258
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
 
6
  import aiohttp
7
  import os
8
 
 
9
  st.set_page_config(layout="wide")
 
 
10
  API_KEY = os.getenv("FMP_API_KEY")
11
 
12
  ########################################
 
54
 
55
  async def fetch_all_8k(pages_to_fetch, from_date, to_date, has_financial):
56
  async with aiohttp.ClientSession() as session:
57
+ tasks = [fetch_8k_page(session, p, from_date, to_date, has_financial)
58
+ for p in range(pages_to_fetch)]
59
  results = []
60
  progress_bar = st.progress(0)
61
  completed = 0
 
86
 
87
  async def fetch_all_company(symbol, filing_type, pages_to_fetch):
88
  async with aiohttp.ClientSession() as session:
89
+ tasks = [fetch_company_page(session, symbol, filing_type, p)
90
+ for p in range(pages_to_fetch)]
91
  results = []
92
  progress_bar = st.progress(0)
93
  completed = 0
 
111
  Use the filters to narrow down the list by filing type, date range, and whether the filing is complete.
112
  """
113
  )
114
+
115
+ # Initialize session state if not set.
116
+ if "live_feed_results" not in st.session_state:
117
+ st.session_state.live_feed_results = None
118
+
119
  with st.sidebar:
120
  with st.expander("Live Feed Filter Parameters", expanded=True):
121
  filing_type = st.selectbox(
 
139
  help="Check to show only filings marked as completed."
140
  )
141
  run_live = st.button("Run Live Feed Query")
 
 
 
142
 
143
+ limit = 500
144
  if run_live:
145
+ st.session_state.live_feed_results = get_live_feed_data(
146
+ limit, filing_type, from_date.isoformat(), to_date.isoformat(), is_done
147
+ )
148
+
149
+ if st.session_state.live_feed_results is not None:
150
  st.write("### Live SEC Filings Data")
151
+ st.dataframe(st.session_state.live_feed_results, use_container_width=True)
152
 
153
  def eight_k_page():
154
  st.title("8-K Filings Specialized")
155
  st.write(
156
  """
157
  This page displays 8-K filings from public companies.
158
+ 8-K filings are reports companies file when major events occur.
159
+ Use the filter below to show only filings that include financial information.
160
  """
161
  )
162
+
163
+ if "eight_k_results" not in st.session_state:
164
+ st.session_state.eight_k_results = None
165
+
166
  with st.sidebar:
167
  with st.expander("8-K Filter Parameters", expanded=True):
168
  from_date = st.date_input(
 
182
  )
183
  has_financial = has_financial_option.lower() == "true"
184
  run_8k = st.button("Run 8-K Query")
185
+
186
+ pages_to_fetch = 15
187
  if run_8k:
188
+ results = asyncio.run(
189
+ fetch_all_8k(pages_to_fetch, from_date.isoformat(), to_date.isoformat(), has_financial)
190
+ )
191
  dfs = [df for df in results if not df.empty]
192
  if dfs:
193
  df_all = pd.concat(dfs, ignore_index=True)
194
+ st.session_state.eight_k_results = df_all
 
195
  else:
196
+ st.session_state.eight_k_results = None
197
  st.warning("No data returned for the given parameters.")
198
 
199
+ if st.session_state.eight_k_results is not None:
200
+ st.write("### 8-K Filings Data")
201
+ st.dataframe(st.session_state.eight_k_results, use_container_width=True)
202
+
203
  def company_specific_page():
204
  st.title("Company Specific SEC Filings")
205
  st.write(
206
  """
207
  This page displays filings for a specific company.
 
208
  Enter a company ticker (e.g., AAPL) and select a filing type (like 10-K or 10-Q) to view the reports.
209
  """
210
  )
211
+
212
+ if "company_results" not in st.session_state:
213
+ st.session_state.company_results = None
214
+ if "company_symbol" not in st.session_state:
215
+ st.session_state.company_symbol = None
216
+
217
  with st.sidebar:
218
  with st.expander("Company Filings Parameters", expanded=True):
219
  symbol = st.text_input(
 
227
  help="Select the type of filing to retrieve."
228
  )
229
  run_company = st.button("Run Company Query")
 
 
230
 
231
+ pages_to_fetch = 10
232
  if run_company:
233
  if symbol.strip():
234
+ results = asyncio.run(
235
+ fetch_all_company(symbol.upper(), filing_type, pages_to_fetch)
236
+ )
237
  dfs = [df for df in results if not df.empty]
238
  if dfs:
239
  df_all = pd.concat(dfs, ignore_index=True)
240
+ st.session_state.company_results = df_all
241
+ st.session_state.company_symbol = symbol.upper()
242
  else:
243
+ st.session_state.company_results = None
244
  st.warning("No filings found for the given parameters.")
245
  else:
246
  st.warning("Please enter a valid company ticker.")
247
 
248
+ if st.session_state.company_results is not None:
249
+ st.write(f"### SEC Filings for {st.session_state.company_symbol}")
250
+ st.dataframe(st.session_state.company_results, use_container_width=True)
251
+
252
  ########################################
253
  # MAIN APPLICATION
254
  ########################################
 
260
  ("Live Feed", "8-K Specialized", "Company Specific"),
261
  help="Navigate to the desired SEC filings page."
262
  )
263
+
264
  if page_selection == "Live Feed":
265
  live_feed_page()
266
  elif page_selection == "8-K Specialized":
 
271
  if __name__ == "__main__":
272
  main()
273
 
 
274
  hide_streamlit_style = """
275
  <style>
276
  #MainMenu {visibility: hidden;}
277
  footer {visibility: hidden;}
278
  </style>
279
  """
280
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)