feature:全球政治经济新闻
This commit is contained in:
+11
-10
@@ -11,6 +11,7 @@ import requests
|
||||
from lxml import etree
|
||||
|
||||
from base import func_english_news
|
||||
from utils.ai.dify_news_analyze import dify_news_title_analyze
|
||||
|
||||
|
||||
class News(object):
|
||||
@@ -70,10 +71,10 @@ class News(object):
|
||||
post = response.json()
|
||||
# 提取content列表 - 避免使用str作为变量名
|
||||
content_list = post.get('data', {}).get('cards', [])
|
||||
|
||||
|
||||
if content_list and len(content_list) > 0:
|
||||
news_items = content_list[0].get('content', [])
|
||||
|
||||
|
||||
# 遍历列表,并格式化每个字典的title, url,然后添加到output字符串中
|
||||
for index, article in enumerate(news_items, start=1):
|
||||
if isinstance(article, dict) and 'word' in article:
|
||||
@@ -81,34 +82,34 @@ class News(object):
|
||||
# url = article.get('url', '')
|
||||
# 使用f-string格式化字符串,并添加到output中
|
||||
output += f"{index} :#{title}\n"
|
||||
|
||||
|
||||
# 输出最终的字符串
|
||||
return output
|
||||
else:
|
||||
self.LOG.error(f"获取百度新闻失败,状态码: {response.status_code}")
|
||||
return "获取百度新闻失败,请稍后再试"
|
||||
|
||||
|
||||
except Exception as e:
|
||||
self.LOG.error(f"获取百度新闻时出错: {e}")
|
||||
return f"获取百度新闻时出错: {e}"
|
||||
|
||||
def get_eng_news(self,website):
|
||||
def get_eng_news(self, website):
|
||||
if website == 'nbc':
|
||||
return func_english_news.nbc()
|
||||
return func_english_news.nbc()
|
||||
elif website == 'cnn':
|
||||
return func_english_news.cnn()
|
||||
return func_english_news.cnn()
|
||||
elif website == 'abc':
|
||||
return func_english_news.abc()
|
||||
elif website == 'fox':
|
||||
return func_english_news.fox()
|
||||
elif website == 'bbc':
|
||||
return func_english_news.bbc()
|
||||
return func_english_news.bbc()
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
news = News()
|
||||
print(news.get_baidu_news())
|
||||
# # msg = "@水牛-分身 今日百度新闻"
|
||||
# # q = re.sub(r"@.*?[\u2005|\s]", "", msg).replace(" ", "")
|
||||
# # print(q)
|
||||
# print(news.get_eng_news('nbc'))
|
||||
# print(news.get_eng_news('nbc'))
|
||||
|
||||
Reference in New Issue
Block a user