adding multiple urls
This commit is contained in:
@@ -5,40 +5,28 @@ from bs4 import BeautifulSoup
|
|||||||
|
|
||||||
os.environ["OPENAI_API_KEY"] = "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"
|
os.environ["OPENAI_API_KEY"] = "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"
|
||||||
|
|
||||||
|
|
||||||
client = OpenAI()
|
client = OpenAI()
|
||||||
|
|
||||||
from openai import OpenAI
|
urls = ['https://klix.ba/', 'https://srpskainfo.com/', 'https://bljesak.info/']
|
||||||
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)
|
for url in urls:
|
||||||
html = response.text
|
response = requests.get(url)
|
||||||
|
html = response.text
|
||||||
|
soup = BeautifulSoup(html, 'html.parser')
|
||||||
|
tags = soup.find_all(['h2', 'p'])
|
||||||
|
|
||||||
soup = BeautifulSoup(html, 'html.parser')
|
prompt_text = ''
|
||||||
onlyText = ' '.join(filter(None, [text.strip() for text in soup.stripped_strings]))
|
for tag in tags:
|
||||||
|
text = tag.get_text(strip=True)
|
||||||
|
prompt_text = prompt_text + text
|
||||||
|
|
||||||
|
completion = client.chat.completions.create(
|
||||||
def takeDataFrom(url):
|
model="gpt-3.5-turbo",
|
||||||
try:
|
messages=[
|
||||||
response = requests.get(url)
|
{"role": "system", "content": "Data analytic, Journalist and News reporter"},
|
||||||
response.raise_for_status()
|
{"role": "user", "content": f"Extract for me evry title and full content for evry title from {prompt_text},without shortening,remove all thing that are not connected to news, make it clear for reading"}
|
||||||
data = response.text
|
]
|
||||||
print(f"Here:{data}")
|
)
|
||||||
return data
|
generated_text = completion.choices[0].message.content
|
||||||
except Exception as e:
|
print(f"Text for {url}: \n {generated_text}\n")
|
||||||
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