Skip to content

Instantly share code, notes, and snippets.

View Raviraj2000's full-sized avatar

Raviraj Shinde Raviraj2000

View GitHub Profile
@Raviraj2000
Raviraj2000 / gotsent.py
Last active October 10, 2021 19:57
GotSent()
sent = list()
for i in tot_val:
sent.append(get_sent(i))
tick_df['sentiment'] = sent
tick_df.head(20)
@Raviraj2000
Raviraj2000 / getaggregate.py
Last active October 10, 2021 19:56
GetAgg()
def get_sent(val):
agg = 0
for i in val:
if i == 'positive':
agg = agg + 1
elif i == 'negative':
agg = agg - 1
if agg > 0:
return('positive')
@Raviraj2000
Raviraj2000 / detect.py
Last active October 10, 2021 19:49
Detect()
def detect(news):
tot_val = list()
for n in news:
if len(n) == 0:
tot_val.append(['neutral'])
else:
inputs = tokenizer(n, return_tensors="pt", padding=True)
outputs = finbert(**inputs)[0]
val = list()
for idx, sent in enumerate(n):
@Raviraj2000
Raviraj2000 / gotdata.py
Created October 10, 2021 19:30
GotData()
news = list()
for i, tick in enumerate(tick_df['tick']):
url = "https://www.tickertape.in/stocks/" + tick + "/news?checklist=basic&ref=stock-overview_overview-sections&type=news"
headlines = get_data(url)
news.append(headlines)
@Raviraj2000
Raviraj2000 / getdata.py
Created October 10, 2021 19:26
GetData()
def get_data(url):
req = Request(url=url,headers={"User-Agent": "Chrome"})
response = urlopen(req).read()
html = BeautifulSoup(response,"html.parser")
news_table = html.find(class_ = 'latest-news-holder')
news = list()
for name_box in news_table.find_all('p', class_='shave-root'):
news.append(name_box.text.strip())
@Raviraj2000
Raviraj2000 / gotticks.py
Last active October 10, 2021 19:19
gotticks()
url = "https://www.tickertape.in/stocks"
tick_df = get_ticks(url)
tick_df.head()
@Raviraj2000
Raviraj2000 / getticks.py
Last active October 10, 2021 19:16
GetTicks()
def get_ticks(url):
req = Request(url=url,headers={"User-Agent": "Chrome"})
response = urlopen(req)
html = BeautifulSoup(response,"html.parser")
ticks_table = html.find(class_ = 'page')
ticks = list()
stocks = list()
for name_box in ticks_table.find_all('a', href = True):
stocks.append(name_box.text.strip())
@Raviraj2000
Raviraj2000 / webscrapeimports.py
Created October 10, 2021 19:02
WebScrapeImport()
from bs4 import BeautifulSoup
import pandas as pd
from urllib.request import urlopen, Request
@Raviraj2000
Raviraj2000 / getaccuracy.py
Created October 10, 2021 08:16
GetAccuracy
from sklearn.metrics import accuracy_score
print(accuracy_score(y, sent_val))
@Raviraj2000
Raviraj2000 / getsent.py
Created October 10, 2021 07:54
GetSent
sent_val = list()
for x in X:
inputs = tokenizer(x, return_tensors="pt", padding=True)
outputs = finbert(**inputs)[0]
val = labels[np.argmax(outputs.detach().numpy())]
print(x, '----', val)
print('#######################################################')
sent_val.append(val)