QuantumLearner commited on
Commit
554e002
·
verified ·
1 Parent(s): 0e084ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -27
app.py CHANGED
@@ -4,13 +4,13 @@ import pandas as pd
4
  import os
5
 
6
  # ---------------------------
7
- # Global Variables (Backend)
8
  # ---------------------------
9
  API_KEY = os.getenv("FMP_API_KEY")
10
  DEFAULT_RSS_PAGE = 0
11
  DEFAULT_SEARCH_NAME = "enotap"
12
  DEFAULT_CIK = "0001916078"
13
- NUM_PAGES = 10 # if applicable, can be used in other endpoints
14
 
15
  # ---------------------------
16
  # Initialize Session State
@@ -35,12 +35,15 @@ if "cik_value" not in st.session_state:
35
  @st.cache_data(show_spinner=False)
36
  def fetch_crowdfunding_rss(page: int) -> pd.DataFrame:
37
  """
38
- Fetch the crowdfunding RSS feed data from the given page.
39
  """
40
  url = f"https://financialmodelingprep.com/api/v4/crowdfunding-offerings-rss-feed?page={page}&apikey={API_KEY}"
41
- response = requests.get(url)
42
- response.raise_for_status()
43
- data = response.json()
 
 
 
44
  if not data:
45
  return pd.DataFrame()
46
  return pd.DataFrame(data)
@@ -51,9 +54,12 @@ def fetch_crowdfunding_search(name: str) -> pd.DataFrame:
51
  Search for crowdfunding campaigns by name.
52
  """
53
  url = f"https://financialmodelingprep.com/api/v4/crowdfunding-offerings/search?name={name}&apikey={API_KEY}"
54
- response = requests.get(url)
55
- response.raise_for_status()
56
- data = response.json()
 
 
 
57
  if not data:
58
  return pd.DataFrame()
59
  return pd.DataFrame(data)
@@ -64,9 +70,12 @@ def fetch_crowdfunding_by_cik(cik: str) -> pd.DataFrame:
64
  Fetch all crowdfunding campaigns launched by a company identified by its CIK.
65
  """
66
  url = f"https://financialmodelingprep.com/api/v4/crowdfunding-offerings?cik={cik}&apikey={API_KEY}"
67
- response = requests.get(url)
68
- response.raise_for_status()
69
- data = response.json()
 
 
 
70
  if not data:
71
  return pd.DataFrame()
72
  return pd.DataFrame(data)
@@ -75,12 +84,12 @@ def fetch_crowdfunding_by_cik(cik: str) -> pd.DataFrame:
75
  # MAIN APP
76
  # ---------------------------
77
  def main():
78
- st.set_page_config(page_title="Crowdfunding Campaigns Dashboard", layout="wide")
79
- st.title("Crowdfunding Campaigns Dashboard")
80
  st.write(
81
- "This dashboard provides access to real-time crowdfunding campaign data. "
82
- "Use the side menu to select one of the three pages below. "
83
- "Each page shows a DataFrame with details fetched from Financial Modeling Prep."
84
  )
85
 
86
  # Sidebar: Navigation and Options
@@ -88,7 +97,11 @@ def main():
88
  page = st.radio(
89
  "Select Page",
90
  ("Crowdfunding RSS Feed", "Crowdfunding Search", "Crowdfunding By CIK"),
91
- help="Choose the page you wish to view. The RSS Feed shows a live feed; Search allows searching by campaign or company name; and By CIK shows campaigns launched by a company using its CIK."
 
 
 
 
92
  )
93
 
94
  if page == "Crowdfunding RSS Feed":
@@ -125,12 +138,12 @@ def main():
125
  st.header("Crowdfunding RSS Feed")
126
  st.write(
127
  "This page displays the latest crowdfunding campaigns from an RSS feed. "
128
- "The data includes various details such as company name, form type, offering amount, and more."
129
  )
130
  if st.session_state.run_rss:
131
  df_rss = fetch_crowdfunding_rss(st.session_state.rss_page)
132
  if df_rss.empty:
133
- st.error("No data returned from the Crowdfunding RSS Feed.")
134
  else:
135
  st.dataframe(df_rss, use_container_width=True)
136
  else:
@@ -139,13 +152,13 @@ def main():
139
  elif page == "Crowdfunding Search":
140
  st.header("Crowdfunding Search")
141
  st.write(
142
- "This page allows you to search for crowdfunding campaigns by company or campaign name. "
143
- "The table below displays the matching campaigns with key details."
144
  )
145
  if st.session_state.run_search:
146
  df_search = fetch_crowdfunding_search(st.session_state.search_name)
147
  if df_search.empty:
148
- st.error("No crowdfunding campaigns found for the specified name.")
149
  else:
150
  st.dataframe(df_search, use_container_width=True)
151
  else:
@@ -154,13 +167,13 @@ def main():
154
  else: # Crowdfunding By CIK
155
  st.header("Crowdfunding By CIK")
156
  st.write(
157
- "This page displays all crowdfunding campaigns launched by a company identified by its CIK. "
158
- "The table below contains detailed information for each campaign."
159
  )
160
  if st.session_state.run_cik:
161
  df_cik = fetch_crowdfunding_by_cik(st.session_state.cik_value)
162
  if df_cik.empty:
163
- st.error("No crowdfunding campaigns found for the specified CIK.")
164
  else:
165
  st.dataframe(df_cik, use_container_width=True)
166
  else:
@@ -176,4 +189,4 @@ hide_streamlit_style = """
176
  footer {visibility: hidden;}
177
  </style>
178
  """
179
- st.markdown(hide_streamlit_style, unsafe_allow_html=True)
 
4
  import os
5
 
6
  # ---------------------------
7
+ # Global Variables
8
  # ---------------------------
9
  API_KEY = os.getenv("FMP_API_KEY")
10
  DEFAULT_RSS_PAGE = 0
11
  DEFAULT_SEARCH_NAME = "enotap"
12
  DEFAULT_CIK = "0001916078"
13
+ NUM_PAGES = 10
14
 
15
  # ---------------------------
16
  # Initialize Session State
 
35
  @st.cache_data(show_spinner=False)
36
  def fetch_crowdfunding_rss(page: int) -> pd.DataFrame:
37
  """
38
+ Fetch the crowdfunding RSS feed data for a specific page.
39
  """
40
  url = f"https://financialmodelingprep.com/api/v4/crowdfunding-offerings-rss-feed?page={page}&apikey={API_KEY}"
41
+ try:
42
+ response = requests.get(url)
43
+ response.raise_for_status()
44
+ data = response.json()
45
+ except:
46
+ return pd.DataFrame()
47
  if not data:
48
  return pd.DataFrame()
49
  return pd.DataFrame(data)
 
54
  Search for crowdfunding campaigns by name.
55
  """
56
  url = f"https://financialmodelingprep.com/api/v4/crowdfunding-offerings/search?name={name}&apikey={API_KEY}"
57
+ try:
58
+ response = requests.get(url)
59
+ response.raise_for_status()
60
+ data = response.json()
61
+ except:
62
+ return pd.DataFrame()
63
  if not data:
64
  return pd.DataFrame()
65
  return pd.DataFrame(data)
 
70
  Fetch all crowdfunding campaigns launched by a company identified by its CIK.
71
  """
72
  url = f"https://financialmodelingprep.com/api/v4/crowdfunding-offerings?cik={cik}&apikey={API_KEY}"
73
+ try:
74
+ response = requests.get(url)
75
+ response.raise_for_status()
76
+ data = response.json()
77
+ except:
78
+ return pd.DataFrame()
79
  if not data:
80
  return pd.DataFrame()
81
  return pd.DataFrame(data)
 
84
  # MAIN APP
85
  # ---------------------------
86
  def main():
87
+ st.set_page_config(page_title="Crowdfunding Campaigns", layout="wide")
88
+ st.title("Crowdfunding Campaigns")
89
  st.write(
90
+ "Access real-time crowdfunding campaign data. "
91
+ "Use the side menu to select from the three pages below. "
92
+ "Each page provides a table with specific campaign details."
93
  )
94
 
95
  # Sidebar: Navigation and Options
 
97
  page = st.radio(
98
  "Select Page",
99
  ("Crowdfunding RSS Feed", "Crowdfunding Search", "Crowdfunding By CIK"),
100
+ help=(
101
+ "Crowdfunding RSS Feed: View live campaign data. "
102
+ "Crowdfunding Search: Find campaigns by name. "
103
+ "Crowdfunding By CIK: Show campaigns for a company by its CIK."
104
+ )
105
  )
106
 
107
  if page == "Crowdfunding RSS Feed":
 
138
  st.header("Crowdfunding RSS Feed")
139
  st.write(
140
  "This page displays the latest crowdfunding campaigns from an RSS feed. "
141
+ "It includes details such as company name, form type, offering amount, and more."
142
  )
143
  if st.session_state.run_rss:
144
  df_rss = fetch_crowdfunding_rss(st.session_state.rss_page)
145
  if df_rss.empty:
146
+ st.error("No data found for the specified RSS page.")
147
  else:
148
  st.dataframe(df_rss, use_container_width=True)
149
  else:
 
152
  elif page == "Crowdfunding Search":
153
  st.header("Crowdfunding Search")
154
  st.write(
155
+ "Search for crowdfunding campaigns by company or campaign name. "
156
+ "The table below shows all matching results."
157
  )
158
  if st.session_state.run_search:
159
  df_search = fetch_crowdfunding_search(st.session_state.search_name)
160
  if df_search.empty:
161
+ st.error("No crowdfunding campaigns found for that name.")
162
  else:
163
  st.dataframe(df_search, use_container_width=True)
164
  else:
 
167
  else: # Crowdfunding By CIK
168
  st.header("Crowdfunding By CIK")
169
  st.write(
170
+ "Shows all crowdfunding campaigns for a company identified by its CIK. "
171
+ "The table below contains details for each campaign."
172
  )
173
  if st.session_state.run_cik:
174
  df_cik = fetch_crowdfunding_by_cik(st.session_state.cik_value)
175
  if df_cik.empty:
176
+ st.error("No crowdfunding campaigns found for that CIK.")
177
  else:
178
  st.dataframe(df_cik, use_container_width=True)
179
  else:
 
189
  footer {visibility: hidden;}
190
  </style>
191
  """
192
+ st.markdown(hide_streamlit_style, unsafe_allow_html=True)