bohmian commited on
Commit
543198a
·
1 Parent(s): 0448b5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -1,10 +1,9 @@
1
  # Importing required modules
2
- import pandas as pd
3
  import numpy as np
4
- import numpy as np
5
- import plotly.express as px
6
 
7
- # To extract and parse fundamental data like beta and growth estimates from finviz website
8
  import requests
9
  from bs4 import BeautifulSoup as bs
10
 
@@ -12,16 +11,18 @@ from bs4 import BeautifulSoup as bs
12
  from urllib.request import urlopen
13
  import json
14
 
 
 
 
 
 
15
  # For Gradio App
16
  import gradio as gr
17
 
18
- import os
19
- # uncomment and set API Key in the environment variable below
20
- # or you can choose to set it using any other method you know
21
- #os.environ['FMP_API_KEY'] = "your_api_key"
22
 
23
- # read the environment variable to use in API requests later
24
- apiKey = os.environ['FMP_API_KEY']
 
25
 
26
 
27
  ############################################################################################################
@@ -31,11 +32,6 @@ apiKey = os.environ['FMP_API_KEY']
31
  # Financialmodelingprep api url
32
  base_url = "https://financialmodelingprep.com/api/v3/"
33
 
34
- def get_jsonparsed_data(url):
35
- response = urlopen(url)
36
- data = response.read().decode("utf-8")
37
- return json.loads(data)
38
-
39
  # get financial statements using financial modelling prep API
40
  def get_financial_statements(ticker):
41
  # quarterly cash flow statements for calculating latest trailing twelve months (TTM) free cash flow
@@ -55,7 +51,7 @@ def get_financial_statements(ticker):
55
 
56
  # quarterly balance sheet statements
57
  columns_drop = ['acceptedDate', 'calendarYear', 'period', 'symbol', 'reportedCurrency', 'cik', 'fillingDate', 'link', 'finalLink']
58
- q_balance_statement = pd.DataFrame(get_jsonparsed_data(base_url+'balance-sheet-statement/' + ticker + '?' + '&apikey=' + apiKey))
59
  q_balance_statement = q_balance_statement.set_index('date').drop(columns_drop, axis=1)
60
  q_balance_statement = q_balance_statement.apply(pd.to_numeric, errors='coerce')
61
 
 
1
  # Importing required modules
2
+ import pandas as pd # for manipulating financial statements in dataframes
3
  import numpy as np
4
+ import plotly.express as px # for visualizing results in interactive plots
 
5
 
6
+ # To extract and parse fundamental data like beta and growth estimates from finviz website's HTML
7
  import requests
8
  from bs4 import BeautifulSoup as bs
9
 
 
11
  from urllib.request import urlopen
12
  import json
13
 
14
+ def get_jsonparsed_data(url):
15
+ response = urlopen(url)
16
+ data = response.read().decode("utf-8")
17
+ return json.loads(data)
18
+
19
  # For Gradio App
20
  import gradio as gr
21
 
 
 
 
 
22
 
23
+ # To read the environment variable to use in API requests later
24
+ import os
25
+ apiKey = os.environ['FMP_API_KEY'] # the environment variable is set in HuggingFace Spaces directly
26
 
27
 
28
  ############################################################################################################
 
32
  # Financialmodelingprep api url
33
  base_url = "https://financialmodelingprep.com/api/v3/"
34
 
 
 
 
 
 
35
  # get financial statements using financial modelling prep API
36
  def get_financial_statements(ticker):
37
  # quarterly cash flow statements for calculating latest trailing twelve months (TTM) free cash flow
 
51
 
52
  # quarterly balance sheet statements
53
  columns_drop = ['acceptedDate', 'calendarYear', 'period', 'symbol', 'reportedCurrency', 'cik', 'fillingDate', 'link', 'finalLink']
54
+ q_balance_statement = pd.DataFrame(get_jsonparsed_data(base_url+'balance-sheet-statement/' + ticker + '?period=quarter' + '&apikey=' + apiKey))
55
  q_balance_statement = q_balance_statement.set_index('date').drop(columns_drop, axis=1)
56
  q_balance_statement = q_balance_statement.apply(pd.to_numeric, errors='coerce')
57