-
Notifications
You must be signed in to change notification settings - Fork 0
/
news.py
33 lines (32 loc) · 1.09 KB
/
news.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
from bs4 import BeautifulSoup
import urllib.request,sys,time
from bs4 import BeautifulSoup
import requests
import pandas as pd
import openai
openai.api_key = "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"
model_engine = "text-davinci-003"
url="https://www.moneycontrol.com/news/business/economy/"
page=requests.get(url)
print(page.status_code)
# print(page.text)
soup = BeautifulSoup(page.text, "html.parser")
links=soup.find_all('li',attrs={'class':'clearfix'})
for i in links:
text=i.find('p').text
if "SBI" in text:
n=text
prompt1="Give me the news sentiment Analysis related to stocks price by giving a score between 0-10: Also give me the stock names that will be affected by this news. Also give me some your analysis in text as well as in score: The news is as follows : %s "%(n)
print(n)
# print(type(text))
completion1 = openai.Completion.create(
engine=model_engine,
prompt=prompt1,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
# print(prompt1)
analysis = completion1.choices[0].text
print(analysis)