-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdescription.py
72 lines (60 loc) · 2.78 KB
/
description.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import streamlit as st
import plotly.graph_objects as go
from GoogleNews import GoogleNews
def objects(ticker, mydb):
mycursor = mydb.cursor()
st.header('Company Description')
try:
query = "SELECT logo_url FROM info_data WHERE ticker='"+ ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
st.image(result[0][0])
query = "SELECT longName FROM info_data WHERE ticker='"+ ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
st.subheader(result[0][0])
query = "SELECT longBusinessSummary FROM info_data WHERE ticker='"+ ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
st.write(result[0][0])
st.subheader("Fundamental Data")
query = "SELECT dividendRate FROM info_data WHERE ticker='"+ ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
st.write(f"Dividend Rate: {result[0][0]}")
query = "SELECT bookValue FROM info_data WHERE ticker='"+ ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
st.write(f"Book Value: {result[0][0]}")
query = "SELECT 52WeekChange FROM info_data WHERE ticker='"+ ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
st.write(f"52 Week Change: {result[0][0]}")
st.subheader("Safety Index")
query = "SELECT dividendRate / beta FROM info_data WHERE ticker='" + ticker +"'"
mycursor.execute(query)
result = mycursor.fetchall()
si = 0
if result[0][0] > 0:
si = max(si, result[0][0])
fig = go.Figure(go.Indicator(
mode = "gauge+number",
value = round(si, 2),
domain = {'x': [0, 1], 'y': [0, 1]},
title = {'text': "Safety Index"},
gauge = {'axis': {'range': [0, 24]},
'bar': {'color': "white"},
'steps' : [
{'range': [0, 8], 'color': "#e3361b"},
{'range': [8, 16], 'color': "#f5e556"},
{'range': [16, 24], 'color': "#45c449"}]}
))
st.plotly_chart(fig)
st.header(f'News on {ticker}')
googlenews = GoogleNews('en')
googlenews.search(ticker)
for i in range(min(5, len(googlenews.results()))):
st.subheader(googlenews.results()[i]['title'])
st.write(googlenews.results()[i]['link'])
except:
st.error(f"There is no data on {ticker} in your database, try pressing the update button.")