Merge pull request 'Added comapny descriptions' (#2) from comp-descriptions into master

Reviewed-on: #2
This commit is contained in:
Aleksander Mendoza-Drosik 2021-06-22 15:43:05 +02:00
commit a18ae37900
2 changed files with 31 additions and 1 deletions

View File

@ -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;
@ -656,3 +656,9 @@ a {
.tab--selected{
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 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"),