-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathst_app.py
107 lines (87 loc) · 3.46 KB
/
st_app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import streamlit as st
import streamlit.components.v1 as components
from datetime import datetime, date, time, timedelta
import pandas as pd
import glob
import os
# Custom Functions
from main import bse_data
# streamlit
st.set_page_config(page_title='App', page_icon=':moneybag:',
layout='wide', initial_sidebar_state='expanded')
st.sidebar.title(':newspaper:' + ' Dashboard')
@st.cache(suppress_st_warning=True)
def footer():
with st.sidebar.expander("Credits"):
st.success('Created by VH')
components.html(
"""
<script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="hirawat" data-color="#FFDD00" data-emoji="☕" data-font="Poppins" data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000" data-coffee-color="#ffffff" ></script>
""",
height=100
)
matching_keywords = ["Presentation", "DRHP", "FDA", "Transcript", "Press Release", "Amalgamation", "Buyback",
"Contract", "Delisting", "Demerger", "Preference Shares", "Annual Report", "Result", "Board Meeting", "Dividend"]
segments = ["Equity", "Debt/Others", "MF/ETFs"]
# Widget
with st.sidebar.form("Input", clear_on_submit=False):
segment = segments[0]
from_date = date.today()
to_date = date.today()
date = from_date.strftime("%d %B %Y")
st.write(":label: Segment :", segment)
st.write(':date: Date :', date)
# st.write('From Date', from_date)
# st.write('To Date', to_date)
button = st.form_submit_button("Reload")
fd = from_date.strftime("%d/%m/%Y")
td = to_date.strftime("%d/%m/%Y")
@st.cache(suppress_st_warning=True)
def get_data():
with st.spinner(text='In progress'):
path, timestamp = bse_data(fd, td, segment)
return path, timestamp
def make_clickable(link):
# target _blank to open new window
# extract clickable text to display for your link
#text = link.split('=')[1]
return f'<a target="_blank" href="{link}">Click Here</a>'
# Main function
def main():
path_csv, timestamp = get_data()
df = pd.read_csv(path_csv)
st.sidebar.write(len(df), "Announcements for Today")
if len(df) == 0:
st.info(
"No Announcements for Today. :fire: Select a Different Date and Rerun. :clown:")
footer()
else:
time = timestamp.strftime('%I:%M %p')
st.sidebar.write(":hourglass: Last Updated ", time) # '%I:%M %p', '%X'
footer()
# Create Matching Keywords Column
keywords = st.multiselect(
"Announcements Category", matching_keywords, default=matching_keywords)
dfc = df.copy()
# Data Analysis
#df = df1
# remove ruplicate links
dfnew = dfc.drop_duplicates(["PDF"])
# link is the column with hyperlinks
dfnew['PDF'] = dfnew['PDF'].apply(make_clickable)
dfnew1 = dfnew.to_html(escape=False)
st.write(dfnew1, unsafe_allow_html=True)
dir = os.getcwd() + "/data/*.html"
file_list = glob.glob(dir)
#files = []
#for f in file_list:
# files = files.append(os.path.basename(f))
c1, c2, c3 = st.columns(3)
c1.success("Data Saved : " + path_csv)
old_file = c2.selectbox("Select from previous files", file_list)
load = c3.button("Load")
if load:
dfold = pd.read_html(old_file)
st.write(dfold)
if __name__ == '__main__':
main()