Spaces:
Running
Running
Robert Castagna
commited on
Commit
·
ac1e18e
1
Parent(s):
817f8a6
update hf app
Browse files- .gitignore +2 -2
- app.py +8 -8
- fin_data_api.py +22 -22
- requirements.txt +3 -4
.gitignore
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
secrets.json
|
| 2 |
fin_data.db
|
| 3 |
-
|
| 4 |
edgar-crawler/
|
| 5 |
-
.venv/
|
|
|
|
| 1 |
secrets.json
|
| 2 |
fin_data.db
|
| 3 |
+
config.json
|
| 4 |
edgar-crawler/
|
| 5 |
+
.venv/
|
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import sqlite3
|
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
import pygwalker as pyg
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
st.set_page_config(
|
|
@@ -12,8 +13,9 @@ st.set_page_config(
|
|
| 12 |
initial_sidebar_state="expanded",
|
| 13 |
)
|
| 14 |
|
| 15 |
-
st.set_title('Financial Data')
|
| 16 |
|
|
|
|
|
|
|
| 17 |
|
| 18 |
conn = sqlite3.connect('fin_data.db')
|
| 19 |
c = conn.cursor()
|
|
@@ -32,13 +34,11 @@ conn.close()
|
|
| 32 |
# Create a DataFrame
|
| 33 |
df = pd.DataFrame(rows, columns=column_names)
|
| 34 |
|
| 35 |
-
# setup pygwalker configuration: https://github.com/Kanaries/pygwalker
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
config = load_config('config.json')
|
| 41 |
-
pyg.walk(df, env='Streamlit', dark='dark', spec=config)
|
| 42 |
|
| 43 |
# show the dataframe just to test
|
| 44 |
st.dataframe(df)
|
|
|
|
| 3 |
import pandas as pd
|
| 4 |
import streamlit as st
|
| 5 |
import pygwalker as pyg
|
| 6 |
+
import streamlit.components.v1 as components
|
| 7 |
|
| 8 |
|
| 9 |
st.set_page_config(
|
|
|
|
| 13 |
initial_sidebar_state="expanded",
|
| 14 |
)
|
| 15 |
|
|
|
|
| 16 |
|
| 17 |
+
st.title('Financial Data')
|
| 18 |
+
st.subheader('This is a BI tool to analyze news sentiment data')
|
| 19 |
|
| 20 |
conn = sqlite3.connect('fin_data.db')
|
| 21 |
c = conn.cursor()
|
|
|
|
| 34 |
# Create a DataFrame
|
| 35 |
df = pd.DataFrame(rows, columns=column_names)
|
| 36 |
|
| 37 |
+
# setup pygwalker configuration: https://github.com/Kanaries/pygwalker, https://docs.kanaries.net/pygwalker/use-pygwalker-with-streamlit.en
|
| 38 |
+
#pyg_html = pyg.to_html(df, dark="dark")
|
| 39 |
+
pyg_html = pyg.walk(df, return_html=True)
|
| 40 |
+
|
| 41 |
+
components.html(pyg_html, height=1000, scrolling=True)
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# show the dataframe just to test
|
| 44 |
st.dataframe(df)
|
fin_data_api.py
CHANGED
|
@@ -49,25 +49,25 @@ c.execute("""create table if not exists company_news (
|
|
| 49 |
)""")
|
| 50 |
|
| 51 |
|
| 52 |
-
res_news = get_finnhub_data('/company-news?symbol=AAPL&from=2023-08-15&to=2023-08-17')
|
| 53 |
-
print(res_news[0].keys())
|
| 54 |
-
for item in res_news:
|
| 55 |
-
dt_object = datetime.datetime.fromtimestamp(item['datetime']).strftime("%Y-%m-%d")
|
| 56 |
-
sentiment = sentiment_analysis(item['headline'])
|
| 57 |
-
sentiment_label = sentiment[0]['label']
|
| 58 |
-
sentiment_score = sentiment[0]['score']
|
| 59 |
-
print(item['headline'], dt_object, sentiment[0]['label'])
|
| 60 |
|
| 61 |
# Prepare your query and data
|
| 62 |
-
query = """
|
| 63 |
-
INSERT INTO company_news
|
| 64 |
-
VALUES (?, ?, ?, ?, ?, ?, ?)
|
| 65 |
-
"""
|
| 66 |
-
data = (item['id'], 'AAPL', item['category'], item['headline'], dt_object, sentiment_label, sentiment_score)
|
| 67 |
|
| 68 |
# Execute the query with the data
|
| 69 |
#c.execute(query, data)
|
| 70 |
-
|
| 71 |
|
| 72 |
rows = c.execute("""
|
| 73 |
select * from company_news
|
|
@@ -81,18 +81,18 @@ df = pd.DataFrame(rows, columns=column_names)
|
|
| 81 |
print(df)
|
| 82 |
|
| 83 |
|
| 84 |
-
# --------------------------------- get basic financials ---------------------------------#
|
| 85 |
|
| 86 |
-
#res_basic_fins = get_finnhub_data('/stock/metric?symbol=AAPL&metric=all')
|
| 87 |
-
#print(res_basic_fins['metric'].keys())
|
| 88 |
-
#print(res_basic_fins['series']['annual'].keys())
|
| 89 |
-
#print(res_basic_fins['series']['quarterly'].keys())
|
| 90 |
|
| 91 |
|
| 92 |
-
# --------------------------------- get insider sentiment --------------------------------- #
|
| 93 |
|
| 94 |
-
#res_sentiment = get_finnhub_data('/stock/insider-sentiment?symbol=AAPL')
|
| 95 |
-
#print(res_sentiment['data'][0].keys())
|
| 96 |
|
| 97 |
|
| 98 |
|
|
|
|
| 49 |
)""")
|
| 50 |
|
| 51 |
|
| 52 |
+
#res_news = get_finnhub_data('/company-news?symbol=AAPL&from=2023-08-15&to=2023-08-17')
|
| 53 |
+
#print(res_news[0].keys())
|
| 54 |
+
#for item in res_news:
|
| 55 |
+
#dt_object = datetime.datetime.fromtimestamp(item['datetime']).strftime("%Y-%m-%d")
|
| 56 |
+
#sentiment = sentiment_analysis(item['headline'])
|
| 57 |
+
#sentiment_label = sentiment[0]['label']
|
| 58 |
+
#sentiment_score = sentiment[0]['score']
|
| 59 |
+
#print(item['headline'], dt_object, sentiment[0]['label'])
|
| 60 |
|
| 61 |
# Prepare your query and data
|
| 62 |
+
# query = """
|
| 63 |
+
# INSERT INTO company_news
|
| 64 |
+
# VALUES (?, ?, ?, ?, ?, ?, ?)
|
| 65 |
+
# """
|
| 66 |
+
# data = (item['id'], 'AAPL', item['category'], item['headline'], dt_object, sentiment_label, sentiment_score)
|
| 67 |
|
| 68 |
# Execute the query with the data
|
| 69 |
#c.execute(query, data)
|
| 70 |
+
|
| 71 |
|
| 72 |
rows = c.execute("""
|
| 73 |
select * from company_news
|
|
|
|
| 81 |
print(df)
|
| 82 |
|
| 83 |
|
| 84 |
+
# # --------------------------------- get basic financials ---------------------------------#
|
| 85 |
|
| 86 |
+
# res_basic_fins = get_finnhub_data('/stock/metric?symbol=AAPL&from=2023-08-15&to=2023-08-17&metric=all')
|
| 87 |
+
# print(res_basic_fins['metric'].keys())
|
| 88 |
+
# print(res_basic_fins['series']['annual'].keys())
|
| 89 |
+
# print(res_basic_fins['series']['quarterly'].keys())
|
| 90 |
|
| 91 |
|
| 92 |
+
# # --------------------------------- get insider sentiment --------------------------------- #
|
| 93 |
|
| 94 |
+
# res_sentiment = get_finnhub_data('/stock/insider-sentiment?symbol=AAPL')
|
| 95 |
+
# print(res_sentiment['data'][0].keys())
|
| 96 |
|
| 97 |
|
| 98 |
|
requirements.txt
CHANGED
|
@@ -8,7 +8,6 @@ requests==2.31.0
|
|
| 8 |
tqdm==4.42.1
|
| 9 |
pathos==0.2.9
|
| 10 |
urllib3==1.26.7
|
| 11 |
-
lxml
|
| 12 |
pandas
|
| 13 |
requests
|
| 14 |
click
|
|
@@ -16,6 +15,6 @@ pathos
|
|
| 16 |
transformers
|
| 17 |
requests
|
| 18 |
datetime
|
| 19 |
-
|
| 20 |
-
streamlit
|
| 21 |
-
|
|
|
|
| 8 |
tqdm==4.42.1
|
| 9 |
pathos==0.2.9
|
| 10 |
urllib3==1.26.7
|
|
|
|
| 11 |
pandas
|
| 12 |
requests
|
| 13 |
click
|
|
|
|
| 15 |
transformers
|
| 16 |
requests
|
| 17 |
datetime
|
| 18 |
+
pygwalker==0.3.9
|
| 19 |
+
streamlit==1.22.0
|
| 20 |
+
lxml==4.9.4
|