SingleArticle
This commit is contained in:
44
pyth/singlearticle.py
Normal file
44
pyth/singlearticle.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import requests
|
||||
from openai import OpenAI
|
||||
import os
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
os.environ["OPENAI_API_KEY"] = "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"
|
||||
|
||||
|
||||
client = OpenAI()
|
||||
|
||||
from openai import OpenAI
|
||||
client = OpenAI()
|
||||
|
||||
url = 'https://srpskainfo.com/tuzilastvo-ih-tek-jutros-obavijestilo-da-istrazuje-debeveca-disciplinski-tuzilac-vsts-trazi-suspenziju-predsjednika-suda-bih/'
|
||||
|
||||
|
||||
response = requests.get(url)
|
||||
html = response.text
|
||||
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
onlyText = ' '.join(filter(None, [text.strip() for text in soup.stripped_strings]))
|
||||
|
||||
|
||||
def takeDataFrom(url):
|
||||
try:
|
||||
response = requests.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.text
|
||||
print(f"Here:{data}")
|
||||
return data
|
||||
except Exception as e:
|
||||
print(f"Error! :{e}")
|
||||
return None
|
||||
|
||||
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "Data analytic"},
|
||||
{"role": "user", "content": f"Extract for me title and full text from :{onlyText},make it clear for reading"}
|
||||
]
|
||||
)
|
||||
|
||||
print(completion.choices[0].message.content)
|
||||
Reference in New Issue
Block a user