From 79bf11aa8ff4d01ad019175a478790d11ea5bbb0 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Tue, 22 Jun 2021 15:41:20 +0200 Subject: [PATCH] Added comapny descriptions --- assets/style.css | 8 +++++++- finance.py | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/assets/style.css b/assets/style.css index ac67f89..635ead2 100755 --- a/assets/style.css +++ b/assets/style.css @@ -645,7 +645,7 @@ a { flex-grow: 1; } -#tab-1, #tab-2{ +#tab-1, #tab-2, #tab-3{ background-color: #1E1E1E; color: #fff; border-left: none; @@ -655,4 +655,10 @@ a { .tab--selected{ background-color: #111111 !important; +} + +#company-desritpion{ + padding: 3rem 1rem; + margin: 0; + background-color: #111111; } \ No newline at end of file diff --git a/finance.py b/finance.py index 7a1e97f..8ee18bb 100755 --- a/finance.py +++ b/finance.py @@ -11,6 +11,8 @@ import pandas as pd import datetime import time from pandas_datareader import data +import requests +from bs4 import BeautifulSoup # Load data stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD', 'AAP', 'AES', 'AFL', 'A', 'APD', 'AKAM', @@ -155,6 +157,9 @@ app.layout = html.Div( dcc.Graph(id='price-dividends', figure=mean_prices_and_dividends_figure, config={'displayModeBar': False}, animate=True), ]), + dcc.Tab(id='tab-3', label='Copmany description', value='tab-3', children=[ + html.Div(id="company-desritpion"), + ]), ]), dash_table.DataTable( id='stock_price_table', @@ -170,6 +175,25 @@ app.layout = html.Div( ) + +# Callback for scraping company description +@app.callback(Output('company-desritpion', 'children'), [Input('table_selector', 'value')]) +def update_graph(selected_dropdown_value): + url = 'https://finance.yahoo.com/quote/{company}/profile?p={company}'.format(company=selected_dropdown_value) + page = requests.get(url) + soup = BeautifulSoup(page.content, 'html.parser') + comp_name = soup.find(id="Main").h3.text + description = soup.find_all('section', class_='quote-sub-section')[0].p.text + + return dcc.Markdown(''' + + # [{comp_name}]({url}) + + {description} + '''.format(comp_name=comp_name,description=description,url=url)) + + + # Callback for downloading file @app.callback( Output("download-data", "data"),