admin管理员组文章数量:1125061
For the last couple of days, my news searcher has been working fine. I searched up the news, and it printed out a list of articles. However I ran it today (without changing it) and it suddenly didn't print anything. I am stumped.
Tried to use different API, but kept on saying my api key was unknown.
My code is right here
import requests
import time
from datetime import date
from newsapi import NewsApiClient
import google.generativeai as genai
import google.generativeai as genai
fileDict={}
textList=[]
responce=requests.get('')
print('welcome to the money-maker 3000!')
time.sleep(0.5)
today=date.today()
def newsSearcher():
question1=input("what news do you want to search? ")
question2=input('sort by (relevancy, popularity, publishedAt?) ')
newsapi = NewsApiClient(api_key='b31f1c87370e4563bb3f1a05be508b4b')
responce=newsapi.get_everything(
q=question1,
sort_by=question2,
from_param=date.today().isoformat()
)
articles=responce.get('articles',[])
for i, article in enumerate(articles, start=1):
print(f"Article {i}:")
print(f" Title: {article['title']}") # Print the title
print(f" Author: {article.get('author', 'N/A')}") # Print the author
print(f" Source: {article['source']['name']}") # Print the source name
print(f" URL: {article['url']}") # Print the URL
print(f" Published At: {article['publishedAt']}") # Print the publication date
print("-"*40)
fileDict.update({i: article['url']})
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
try:
from newspaper import Article
from newspaper.article import ArticleException
articleUrl=fileDict.get(i)
response = requests.get(articleUrl, headers=headers)
articleReal=Article(articleUrl)
articleReal.set_html(response.text)
articleReal.download()
articleReal.parse()
textList.append(articleReal.text)
except:
print('failed to download article')
ques3=input('would you like to view an article? ')
if ques3=='yes' or ques3=='y':
ques4=input('number of article for viewing? ')
ques4int=int(ques4)
print(textList[ques4int])
newsSearcher()
if ques3=='no' or ques3=='n':
ques5=input('would you instead like an ai overview? ')
if ques5=='yes' or ques5=='y':
print('setting up gemini ai')
genai.configure(api_key="AIzaSyCE065W67-hB4TiXuaCnBy6iOwGfaj9wMI")
model = genai.GenerativeModel("gemini-1.5-flash")
thingy = model.generate_content(f"Generate summary of all of these articles {textList}")
print(thingy.text)
ques6=input('more questions? ')
if ques6=='yes' or ques6=='y':
def convo():
ques7=input('question about articles ')
model2=genai.GenerativeModel("gemini-1.5-flash")
answer=model.generate_content(f" Generate a responce based off of the articles and question. {ques7} {textList}")
print(answer.text)
ques8=input('have another question? ')
if ques8=='yes' or'y':
convo()
else:
newsSearcher()
convo()
else:
newsSearcher()
else:
newsSearcher()
newsSearcher()
exit=input('input to exit ')
本文标签: pythonArticle Searcher turns up blankStack Overflow
版权声明:本文标题:python - Article Searcher turns up blank - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736658885a1946324.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论