news
This commit is contained in:
2024-12-20 15:10:33 +08:00
parent 675953551c
commit 457be8eb9d
13 changed files with 613 additions and 19 deletions
+80 -1
View File
@@ -10,6 +10,8 @@ from datetime import datetime
import requests
from lxml import etree
from base import func_english_news
class News(object):
def __init__(self) -> None:
@@ -46,6 +48,83 @@ class News(object):
return f"{fmt_time} {self.week[weekday_news]}\n{fmt_news}"
def get_36kr_news(self):
url = "https://orz.ai/dailynews/?platform=36kr"
# 获取当前日期和英文星期名
now = datetime.now()
current_date = now.strftime("%Y年%m月%d")
english_weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
chinese_weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
# 将英文星期名映射为中文
current_weekday_index = now.weekday() # 获取当前是星期几(0代表星期一,6代表星期日)
current_weekday_chinese = chinese_weekdays[current_weekday_index]
# 初始化一个空字符串来存储结果
output = f"当前日期:{current_date} {current_weekday_chinese}\n\n"
response = requests.get(url)
if response.status_code == 200:
post = response.json()
str = post['data']
# 遍历列表,并格式化每个字典的title, url,然后添加到output字符串中
for index, article in enumerate(str, start=1):
title = article['title']
url = article['url']
# 使用f-string格式化字符串,并添加到output中
output += f"{index}. 标题: {title}\n URL: {url}\n"
# 输出最终的字符串(这里只是为了展示,实际上你可以根据需要处理这个字符串)
return output
def get_baidu_news(self):
url = "https://orz.ai/dailynews/?platform=baidu"
# 获取当前日期和英文星期名
now = datetime.now()
current_date = now.strftime("%Y年%m月%d")
english_weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
chinese_weekdays = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
# 将英文星期名映射为中文
current_weekday_index = now.weekday() # 获取当前是星期几(0代表星期一,6代表星期日)
current_weekday_chinese = chinese_weekdays[current_weekday_index]
# 初始化一个空字符串来存储结果
output = f"当前日期:{current_date} {current_weekday_chinese}\n\n"
response = requests.get(url)
if response.status_code == 200:
post = response.json()
str = post['data']
# 遍历列表,并格式化每个字典的title, url,然后添加到output字符串中
for index, article in enumerate(str, start=1):
title = article['title']
# url = article['url']
# 使用f-string格式化字符串,并添加到output中
output += f"{index}. : {title}\n"
# 输出最终的字符串(这里只是为了展示,实际上你可以根据需要处理这个字符串)
return output
def get_eng_news(self,website):
if website == 'nbc':
return func_english_news.nbc()
elif website == '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()
if __name__ == "__main__":
news = News()
print(news.get_important_news())
# print(news.get_baidu_news())
# msg = "@水牛-分身 今日百度新闻"
# q = re.sub(r"@.*?[\u2005|\s]", "", msg).replace(" ", "")
# print(q)
print(news.get_eng_news('nbc'))