implemented assets_debts route in backend

This commit is contained in:
Claudio Maggioni 2023-05-24 09:58:06 +02:00
parent f09b092639
commit 437ca39b02
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,21 @@
import pandas as pd
import numpy as np
import os
ROOT_PATH: str = os.path.join(os.path.dirname(__file__), '..', '..')
def compare_balance_sheets(ticker_list: list):
df_ret = pd.DataFrame(columns=['total_assets', 'current_assets', 'total_debt', 'current_debt'])
for i, ticker in enumerate(ticker_list):
assets_debt = pd.read_csv(ROOT_PATH + r'/Companies_Data/' + ticker + '_Data/' + ticker + '_balance_sheet_4Y+4Q.csv')
selected_data = assets_debt[['TotalAssets', 'TotalDebt', 'CurrentAssets', 'CurrentDebt']]
df_ret.loc[ticker, 'total_assets'] = selected_data.iloc[0]['TotalAssets']
df_ret.loc[ticker, 'current_assets'] = selected_data.iloc[0]['TotalDebt']
df_ret.loc[ticker, 'total_debt'] = selected_data.iloc[0]['CurrentAssets']
df_ret.loc[ticker, 'current_debt'] = selected_data.iloc[0]['CurrentDebt']
df_ret.index.name = 'ticker'
return df_ret.reset_index(drop=False).replace({ np.nan: None }).to_dict('records')

View file

@ -4,6 +4,7 @@ from backend.utils.build_frontend import build_frontend
from backend.api.companies import get_companies from backend.api.companies import get_companies
from backend.api.closing_price import get_closing_price_hist from backend.api.closing_price import get_closing_price_hist
from backend.api.employees import get_employees from backend.api.employees import get_employees
from backend.api.assets_debts import compare_balance_sheets
import os import os
import sys import sys
import subprocess import subprocess
@ -40,6 +41,11 @@ def price_history(tickers: Optional[str]) -> object:
return jsonify(get_closing_price_hist(tickers.split('/'))) return jsonify(get_closing_price_hist(tickers.split('/')))
@app.route('/assets_debts/<path:tickers>', methods=['GET'])
def assets_debts(tickers: Optional[str]) -> object:
return jsonify(compare_balance_sheets(tickers.split('/')))
@app.route('/companies/logos/<ticker>') @app.route('/companies/logos/<ticker>')
def get_company_logo(ticker: str): def get_company_logo(ticker: str):
logo_dir: str = os.path.join(ROOT_DIR, 'scraper', 'logos', 'logos') logo_dir: str = os.path.join(ROOT_DIR, 'scraper', 'logos', 'logos')