Spaces:
Sleeping
Sleeping
app.py
CHANGED
|
@@ -2,8 +2,6 @@ import streamlit as st
|
|
| 2 |
from urllib.request import urlopen, Request
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
import pandas as pd
|
| 5 |
-
import plotly
|
| 6 |
-
import plotly.express as px
|
| 7 |
import json # for graph plotting in website
|
| 8 |
# NLTK VADER for sentiment analysis
|
| 9 |
import nltk
|
|
@@ -85,25 +83,6 @@ def score_news(parsed_news_df):
|
|
| 85 |
|
| 86 |
return parsed_and_scored_news
|
| 87 |
|
| 88 |
-
|
| 89 |
-
def plot_hourly_sentiment(parsed_and_scored_news, ticker):
|
| 90 |
-
|
| 91 |
-
# Group by date and ticker columns from scored_news and calculate the mean
|
| 92 |
-
mean_scores = parsed_and_scored_news.resample('H').mean()
|
| 93 |
-
|
| 94 |
-
# Plot a bar chart with plotly
|
| 95 |
-
fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score', title = ticker + ' Hourly Sentiment Scores')
|
| 96 |
-
return fig # instead of using fig.show(), we return fig and turn it into a graphjson object for displaying in web page later
|
| 97 |
-
|
| 98 |
-
def plot_daily_sentiment(parsed_and_scored_news, ticker):
|
| 99 |
-
|
| 100 |
-
# Group by date and ticker columns from scored_news and calculate the mean
|
| 101 |
-
mean_scores = parsed_and_scored_news.resample('D').mean()
|
| 102 |
-
|
| 103 |
-
# Plot a bar chart with plotly
|
| 104 |
-
fig = px.bar(mean_scores, x=mean_scores.index, y='sentiment_score', title = ticker + ' Daily Sentiment Scores')
|
| 105 |
-
return fig # instead of using fig.show(), we return fig and turn it into a graphjson object for displaying in web page later
|
| 106 |
-
|
| 107 |
# for extracting data from finviz
|
| 108 |
finviz_url = 'https://finviz.com/quote.ashx?t='
|
| 109 |
|
|
@@ -121,7 +100,6 @@ try:
|
|
| 121 |
parsed_news_df = parse_news(news_table)
|
| 122 |
print(parsed_news_df)
|
| 123 |
parsed_and_scored_news = score_news(parsed_news_df)
|
| 124 |
-
|
| 125 |
st.table(parsed_and_scored_news)
|
| 126 |
|
| 127 |
except Exception as e:
|
|
|
|
| 2 |
from urllib.request import urlopen, Request
|
| 3 |
from bs4 import BeautifulSoup
|
| 4 |
import pandas as pd
|
|
|
|
|
|
|
| 5 |
import json # for graph plotting in website
|
| 6 |
# NLTK VADER for sentiment analysis
|
| 7 |
import nltk
|
|
|
|
| 83 |
|
| 84 |
return parsed_and_scored_news
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# for extracting data from finviz
|
| 87 |
finviz_url = 'https://finviz.com/quote.ashx?t='
|
| 88 |
|
|
|
|
| 100 |
parsed_news_df = parse_news(news_table)
|
| 101 |
print(parsed_news_df)
|
| 102 |
parsed_and_scored_news = score_news(parsed_news_df)
|
|
|
|
| 103 |
st.table(parsed_and_scored_news)
|
| 104 |
|
| 105 |
except Exception as e:
|