Added comapny descriptions #2

Merged
s434749 merged 1 commits from comp-descriptions into master 2021-06-22 15:43:06 +02:00
2 changed files with 31 additions and 1 deletions
Showing only changes of commit 79bf11aa8f - Show all commits

View File

@ -645,7 +645,7 @@ a {
flex-grow: 1; flex-grow: 1;
} }
#tab-1, #tab-2{ #tab-1, #tab-2, #tab-3{
background-color: #1E1E1E; background-color: #1E1E1E;
color: #fff; color: #fff;
border-left: none; border-left: none;
@ -656,3 +656,9 @@ a {
.tab--selected{ .tab--selected{
background-color: #111111 !important; background-color: #111111 !important;
} }
#company-desritpion{
padding: 3rem 1rem;
margin: 0;
background-color: #111111;
}

View File

@ -11,6 +11,8 @@ import pandas as pd
import datetime import datetime
import time import time
from pandas_datareader import data from pandas_datareader import data
import requests
from bs4 import BeautifulSoup
# Load data # Load data
stock_list = ['MMM', 'ABT', 'ABBV', 'ABMD', 'ACN', 'ATVI', 'ADBE', 'AMD', 'AAP', 'AES', 'AFL', 'A', 'APD', 'AKAM', 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, dcc.Graph(id='price-dividends', figure=mean_prices_and_dividends_figure,
config={'displayModeBar': False}, animate=True), 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( dash_table.DataTable(
id='stock_price_table', 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 # Callback for downloading file
@app.callback( @app.callback(
Output("download-data", "data"), Output("download-data", "data"),