epic
news
This commit is contained in:
263
base/func_english_news.py
Normal file
263
base/func_english_news.py
Normal file
@@ -0,0 +1,263 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Program: English Daily News Downloader
|
||||
Author: MrCrawL
|
||||
Created Date: 2024-01-21
|
||||
Last Modified: 2024-03-24
|
||||
Modified by: MrCrawL
|
||||
"""
|
||||
'''Existing problem: text with hyperlink won't be saved'''
|
||||
|
||||
import requests
|
||||
from time import localtime, sleep
|
||||
from lxml import etree
|
||||
|
||||
|
||||
def get_time():
|
||||
date_ = f'{str(localtime().tm_year).zfill(4)}-{str(localtime().tm_mon).zfill(2)}-{str(localtime().tm_mday).zfill(2)}'
|
||||
return date_
|
||||
|
||||
|
||||
# delete duplicated
|
||||
def title_tidy(title_list):
|
||||
t_index = []
|
||||
for i in range(1, len(title_list)):
|
||||
if title_list[i] == title_list[i - 1]: t_index.append(i)
|
||||
t_index.reverse()
|
||||
for i in range(len(t_index)): title_list.pop(t_index[i])
|
||||
return title_list
|
||||
|
||||
|
||||
# tidy text, seems a little bit redundant
|
||||
def text_tidy(p_text):
|
||||
text_ = p_text.replace('’', "'")
|
||||
text_ = text_.replace(' \n\n', ' ')
|
||||
text_ = text_.replace('\n\n ', ' ')
|
||||
text_ = text_.replace('\n\n,', ' ,')
|
||||
text_ = text_.replace(',\n\n', ', ')
|
||||
text_ = text_.replace(';\n\n', '; ')
|
||||
text_ = text_.replace('\n\n;', ' ;')
|
||||
text_ = text_.replace(':\n\n', ': ')
|
||||
text_ = text_.replace('\n\n:', ' :')
|
||||
text_ = text_.replace('"\n\n', '" ')
|
||||
text_ = text_.replace('\n\n"', ' "')
|
||||
text_ = text_.replace("'\n\n", "' ")
|
||||
text_ = text_.replace("\n\n'", " '")
|
||||
return text_
|
||||
|
||||
|
||||
def save(text, file_name, mode='w', encoding='utf-8'):
|
||||
with open(f'{file_name}.txt', mode, encoding=encoding) as f: f.write(text)
|
||||
|
||||
|
||||
def nbc():
|
||||
url = 'https://www.nbcnews.com/'
|
||||
res = requests.get(url)
|
||||
html = etree.HTML(res.text)
|
||||
href = html.xpath('//h2/a/@href')
|
||||
href = title_tidy(href)
|
||||
# quant = int(input(f'There are {len(href)} pieces detected. How many would you download:'))
|
||||
# if quant > len(href) or quant < 1:
|
||||
# print("Outnumber!")
|
||||
# quit()
|
||||
count = 0
|
||||
# save('', f'NBC_news_title_{get_time()}')
|
||||
# save('', f'NBC_news_text_{get_time()}')
|
||||
msg =''
|
||||
for i in range(30):
|
||||
url = href[i]
|
||||
sleep(0.1) # delete to speed up
|
||||
res = requests.get(url)
|
||||
html = etree.HTML(res.text)
|
||||
title = html.xpath('//h1/text()')
|
||||
if len(title) == 0:
|
||||
print(f'Video or other news. Link: {url}')
|
||||
continue
|
||||
title = title[0]
|
||||
author = html.xpath('//span[@class="byline-name"]/a/text() | //span[@class="byline-name" and not(a)]/text()')
|
||||
author = ', '.join(author)
|
||||
text = html.xpath('//p[@class=""]/text()')
|
||||
text = '\n\n'.join(text)
|
||||
text = text_tidy(text)
|
||||
count += 1
|
||||
# save(f'Title: {title}\nLink: {url}\n\n', f'NBC_news_title_{get_time()}', 'a') # news title
|
||||
# save(f'Title: {title}\n\nOrigin: {url}\n\nAuthor: {author}\n\n\n', f'NBC_news_text_{get_time()}', 'a')
|
||||
# save(f'{text}' + '\n\n------------------------------\n\n', f'NBC_news_text_{get_time()}', 'a')
|
||||
# print(f'Title: {title}. Link: {href[i]}.')
|
||||
msg += f'Title: {title}. Link: {href[i]}.\n'
|
||||
return msg
|
||||
|
||||
|
||||
def cnn():
|
||||
head = 'https://www.cnn.com'
|
||||
res = requests.get(head + '/')
|
||||
html = etree.HTML(res.text)
|
||||
href = html.xpath('//a[@data-link-type="article"]/@href')
|
||||
href = title_tidy(href)
|
||||
# quant = int(input(f'{len(href)} data detected. How many would you like to download:'))
|
||||
# if quant > len(href) or quant < 1:
|
||||
# print("Outnumber!")
|
||||
# quit()
|
||||
count = 0
|
||||
msg = ''
|
||||
# save('', f'CNN_news_title_{get_time()}')
|
||||
# save('', f'CNN_news_text_{get_time()}')
|
||||
for i in range(30):
|
||||
url = head + href[i]
|
||||
sleep(0.1) # delete to speed up
|
||||
res = requests.get(url)
|
||||
html = etree.HTML(res.text)
|
||||
title = html.xpath('//h1[@data-editable="headlineText"]/text()')
|
||||
if len(title) == 0:
|
||||
print(f'Video or other news. Link: {url}')
|
||||
continue
|
||||
title = title[0].strip()
|
||||
author = html.xpath('//span[@class="byline__name"]/text()')
|
||||
author = ', '.join(author)
|
||||
text = html.xpath('//p[@class="paragraph inline-placeholder"]/text()')
|
||||
for k in range(len(text)): text[k].strip()
|
||||
text = ''.join(text)
|
||||
text = text_tidy(text)
|
||||
count += 1
|
||||
# save(f'Title: {title}\nLink: {url}\n\n', f'CNN_news_title_{get_time()}', 'a') # news title
|
||||
# save(f'Title: {title}\n\nOrigin: {url}\n\nAuthor: {author}\n\n\n', f'CNN_news_text_{get_time()}', 'a')
|
||||
# save(f'{text}' + '\n\n------------------------------\n\n', f'CNN_news_text_{get_time()}', 'a')
|
||||
# print(f'Title: {title}. Link: {url}')
|
||||
msg +=f'Title: {title}. Link: {url}\n'
|
||||
# print(f'Files saved with {count} articles available.')
|
||||
return msg
|
||||
|
||||
def abc():
|
||||
head = 'https://abcnews.go.com/'
|
||||
res = requests.get(head)
|
||||
html = etree.HTML(res.text)
|
||||
href1 = html.xpath('//div[@class="HeadlinesTrio"]/a/@href')
|
||||
href2 = html.xpath('//div[@class="title card"]/a[@class="AnchorLink"]/@href | //div[@class="title"]/a[@class="AnchorLink"]/@href')
|
||||
href3 = html.xpath('//a[@target="_self"]/@href')
|
||||
href4 = html.xpath('//a[@class="AnchorLink VideoTile"]/@href')
|
||||
href = href1 + href2 + href3 + href4
|
||||
href = title_tidy(href)
|
||||
# quant = int(input(f'{len(href)} data detected. How many would you like to download:'))
|
||||
# if quant > len(href) or quant < 1:
|
||||
# print("Outnumber!")
|
||||
# quit()
|
||||
count = 0
|
||||
msg = ''
|
||||
# save('', f'ABC_news_title_{get_time()}')
|
||||
# save('', f'ABC_news_text_{get_time()}')
|
||||
for i in range(30):
|
||||
url = href[i]
|
||||
sleep(0.1) # delete to speed up
|
||||
res = requests.get(url)
|
||||
html = etree.HTML(res.text)
|
||||
title = html.xpath('//div[@data-testid="prism-headline"]/h1/text()')
|
||||
if len(title) == 0:
|
||||
print(f'Video or other news. Link: {url}')
|
||||
continue
|
||||
title = title[0]
|
||||
author = html.xpath('//a[@data-testid="prism-linkbase"]/text()')
|
||||
author = ', '.join(author)
|
||||
text = html.xpath('//div[@data-testid="prism-article-body"]/p/text()')
|
||||
text = '\n\n'.join(text)
|
||||
text = text_tidy(text)
|
||||
count += 1
|
||||
# save(f'Title: {title}\nLink: {url}\n\n', f'ABC_news_title_{get_time()}', 'a') # news title
|
||||
# save(f'Title: {title}\n\nOrigin: {url}\n\nAuthor: {author}\n\n\n', f'ABC_news_text_{get_time()}', 'a')
|
||||
# save(f'{text}' + '\n\n------------------------------\n\n', f'ABC_news_text_{get_time()}', 'a')
|
||||
# print(f'Title: {title}. Link: {url}')
|
||||
msg +=f'Title: {title}. Link: {url}\n'
|
||||
# print(f'Files saved with {count} articles available.')
|
||||
return msg
|
||||
|
||||
def fox():
|
||||
head = 'https://www.foxnews.com/'
|
||||
res = requests.get(head)
|
||||
html = etree.HTML(res.text)
|
||||
href = html.xpath('//h3[@class="title"]/a/@href')
|
||||
href = title_tidy(href)
|
||||
# quant = int(input(f'{len(href)} data detected. How many would you like to download:'))
|
||||
# if quant > len(href) or quant < 1:
|
||||
# print("Outnumber!")
|
||||
# quit()
|
||||
count = 0
|
||||
msg =''
|
||||
# save('', f'FOX_news_title_{get_time()}')
|
||||
# save('', f'FOX_news_text_{get_time()}')
|
||||
for i in range(30):
|
||||
if href[i][0:4] != 'http': href[i] = 'https:' + href[i]
|
||||
url = href[i]
|
||||
sleep(0.1) # delete to speed up
|
||||
res = requests.get(url)
|
||||
html = etree.HTML(res.text)
|
||||
title = html.xpath('//h1[@itemprop="headline"]/text()')
|
||||
if len(title) == 0:
|
||||
print(f'Video or other news. Link: {url}')
|
||||
continue
|
||||
title = title[0]
|
||||
author = html.xpath('//a[@rel="author"]/strong/text()')
|
||||
author = ', '.join(author)
|
||||
text = html.xpath('//div[@itemprop="articleBody"]/p/text()')
|
||||
text = '\n\n'.join(text)
|
||||
text = text_tidy(text)
|
||||
count += 1
|
||||
# save(f'Title: {title}\nLink: {url}\n\n', f'FOX_news_title_{get_time()}', 'a') # news title
|
||||
# save(f'Title: {title}\n\nOrigin: {url}\n\nAuthor: {author}\n\n\n', f'FOX_news_text_{get_time()}', 'a')
|
||||
# save(f'{text}' + '\n\n------------------------------\n\n', f'FOX_news_text_{get_time()}', 'a')
|
||||
# print(f'Title: {title}. Link: {url}')
|
||||
msg +=f'Title: {title}. Link: {url}\n'
|
||||
# print(f'Files saved with {count} articles available.')
|
||||
return msg
|
||||
|
||||
def bbc():
|
||||
head = 'https://www.bbc.com'
|
||||
res = requests.get(head + '/')
|
||||
html = etree.HTML(res.text)
|
||||
href = html.xpath('//h2[@data-testid="card-headline"]/../../../../../@href | //h2[@data-testid="card-headline"]/../../../../@href')
|
||||
href = title_tidy(href)
|
||||
# quant = int(input(f'{len(href)} data detected. How many would you like to download:'))
|
||||
# if quant > len(href) or quant < 1:
|
||||
# print("Outnumber!")
|
||||
# quit()
|
||||
count = 0
|
||||
msg =''
|
||||
# save('', f'BBC_news_title_{get_time()}')
|
||||
# save('', f'BBC_news_text_{get_time()}')
|
||||
for i in range(30):
|
||||
if href[i][0:4] == 'http': continue
|
||||
url = head + href[i]
|
||||
sleep(0.1) # delete to speed up
|
||||
print(url)
|
||||
res = requests.get(url)
|
||||
html = etree.HTML(res.text)
|
||||
title = html.xpath('//div[@data-component="headline-block"]/h1/text()')
|
||||
if len(title) == 0:
|
||||
# print(f'Video or other news. Link: {url}')
|
||||
continue
|
||||
title = title[0]
|
||||
# author = html.xpath('//div[@data-testid="byline"]/div/span[@data-testid="byline-name"]/text()')
|
||||
# author = ', '.join(author)
|
||||
# text = html.xpath('//div[@data-component="text-block"]/p/b/text() | //div[@data-component="text-block"]/p/text()')
|
||||
# text = '\n\n'.join(text)
|
||||
# text = text_tidy(text)
|
||||
count += 1
|
||||
# save(f'Title: {title}\nLink: {url}\n\n', f'BBC_news_title_{get_time()}', 'a') # news title
|
||||
# save(f'Title: {title}\n\nOrigin: {url}\n\nAuthor: {author}\n\n\n', f'BBC_news_text_{get_time()}', 'a')
|
||||
# save(f'{text}' + '\n\n------------------------------\n\n', f'BBC_news_text_{get_time()}', 'a')
|
||||
# print(f'Title: {title}. Link: {url}')
|
||||
|
||||
msg +=f'Title: {title}. Link: {url}\n'
|
||||
# print(f'Files saved with {count} articles available.')
|
||||
return msg
|
||||
|
||||
if __name__ == '__main__':
|
||||
# Hello, World! :)
|
||||
# news = input('Choose news site["nbc","cnn","abc","fox","bbc"]:').lower()
|
||||
# if news == 'nbc': nbc()
|
||||
# elif news == 'cnn': cnn()
|
||||
# elif news == 'abc': abc()
|
||||
# elif news == 'fox': fox()
|
||||
# elif news == 'bbc': bbc()
|
||||
# else:
|
||||
# print('Oops! It seems a wrong input. Please retry...')
|
||||
# sleep(2)
|
||||
print(bbc())
|
||||
66
base/func_epic.py
Normal file
66
base/func_epic.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Time : 2022/12/29 15:51
|
||||
# @Author : 南宫乘风
|
||||
# @Email : 1794748404@qq.com
|
||||
# @File : epic.py
|
||||
# @Software: PyCharm
|
||||
from datetime import datetime
|
||||
import json
|
||||
import re
|
||||
import time
|
||||
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def is_friday():
|
||||
today = datetime.today()
|
||||
return today.weekday() == 4 # Monday is 0 and Sunday is 6, so Friday is 4
|
||||
|
||||
|
||||
|
||||
def get_free():
|
||||
url = 'https://steamstats.cn/xi'
|
||||
headers = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36 Edg/90.0.818.41'}
|
||||
r = requests.get(url, headers=headers)
|
||||
r.raise_for_status()
|
||||
r.encoding = r.apparent_encoding
|
||||
soup = BeautifulSoup(r.text, "html.parser")
|
||||
text = "今日喜加一 :" + 'https://store.epicgames.com/en-US/free-games' +'\n'
|
||||
|
||||
tbody = soup.find('tbody')
|
||||
tr = tbody.find_all('tr')
|
||||
i = 1
|
||||
for tr in tr:
|
||||
td = tr.find_all('td')
|
||||
a_tags = td[6].find_all('a')
|
||||
for a in a_tags:
|
||||
href_value = a.get('href')
|
||||
name = td[1].string.strip().replace('\n', '').replace('\r', '')
|
||||
gametype = td[2].string.replace(" ", "").replace('\n', '').replace('\r', '')
|
||||
start = td[3].string.replace(" ", "").replace('\n', '').replace('\r', '')
|
||||
end = td[4].string.replace(" ", "").replace('\n', '').replace('\r', '')
|
||||
time = td[5].string.replace(" ", "").replace('\n', '').replace('\r', '')
|
||||
oringin = td[6].find('span').string.replace(" ", "").replace('\n', '').replace('\r', '')
|
||||
|
||||
text = (text + "序号:" + str(
|
||||
i) + '\n' + "游戏名称:" + name + '\n'
|
||||
+ "DLC/game:" + gametype + '\n'
|
||||
+ "开始时间:" + start + '\n'
|
||||
+ "结束时间:" + end + '\n'
|
||||
+ "是否永久:" + time + '\n'
|
||||
+ "平台:" + oringin + '\n'
|
||||
+ "URL:" + href_value + '\n'
|
||||
)
|
||||
|
||||
# print(text)
|
||||
i=i+1
|
||||
|
||||
return text
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(get_free())
|
||||
# if len(game_info) > 40:
|
||||
|
||||
# send_to_epic_message(get_free())
|
||||
@@ -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'))
|
||||
8
base/func_txt_speech.py
Normal file
8
base/func_txt_speech.py
Normal file
@@ -0,0 +1,8 @@
|
||||
import pyttsx3
|
||||
engine = pyttsx3.init()
|
||||
engine.setProperty('rate', 150)
|
||||
engine.setProperty('volume', 0.9)
|
||||
engine.setProperty('voice', 'zh-CN') # 选择中文语音风格
|
||||
text = '你好,世界!'
|
||||
engine.say(text)
|
||||
engine.runAndWait()
|
||||
@@ -1,7 +1,7 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
from sparkdesk_web.core import SparkWeb
|
||||
|
||||
import re
|
||||
|
||||
class XinghuoWeb:
|
||||
def __init__(self, xhconf=None) -> None:
|
||||
@@ -27,6 +27,8 @@ class XinghuoWeb:
|
||||
|
||||
def get_answer(self, msg: str, sender: str = None) -> str:
|
||||
answer = self._chat.chat(msg)
|
||||
answer = re.sub(r'```.*?```', '', answer, flags=re.DOTALL)
|
||||
answer = re.sub(r'^\s*$\n', '', answer, flags=re.MULTILINE)
|
||||
return answer
|
||||
|
||||
|
||||
@@ -34,5 +36,63 @@ if __name__ == "__main__":
|
||||
from configuration import Config
|
||||
c = Config()
|
||||
xinghuo = XinghuoWeb(c.XINGHUO_WEB)
|
||||
rsp = xinghuo.get_answer("你还活着?")
|
||||
question = \
|
||||
"请根据新闻标题,按照新闻的类型(财经、彩票、房产、股票、家居、教育、科技、社会、时尚、时政、体育、星座、游戏、娱乐)进行分类;内容前加入当前日期和星期几" \
|
||||
"对分类下的内容格式如下:" \
|
||||
"1.#标题1" \
|
||||
"2.#标题2" \
|
||||
"分类使用--号进行分组,无内容则忽略该分组" \
|
||||
"当前日期:2024年12月16日 星期一" \
|
||||
"1. 标题: 安徽监狱回应李铁可否在监狱踢球" \
|
||||
"2. 标题: 董明珠问雷军:你给股民分了多少钱?" \
|
||||
"3. 标题: 学习贯彻中央经济工作会议精神" \
|
||||
"4. 标题: 网曝阿娇知三当三" \
|
||||
"5. 标题: 当我用人民币感受台湾物价" \
|
||||
"6. 标题: 男子坐轮椅在高速疾驰" \
|
||||
"7. 标题: 刘亦菲陈金飞酒店聚餐" \
|
||||
"8. 标题: 冷冷冷冷冷你冷冷冷冷冷" \
|
||||
"9. 标题: 男生表演引体向上手滑摔到女生怀里" \
|
||||
"10. 标题: 74岁斯琴高娃自曝近况" \
|
||||
"11. 标题: 12岁女孩感染HPV 17岁男友被抓" \
|
||||
"12. 标题: 高校女生被殴打需植入钢钉?谣言" \
|
||||
"13. 标题: 东京将启动上四休三工作制" \
|
||||
"14. 标题: 张杰谢娜回应婚变传闻" \
|
||||
"15. 标题: 董明珠:小米空调因侵权赔了格力50万" \
|
||||
"16. 标题: 汪峰女友森林北晒近况" \
|
||||
"17. 标题: 实习生一句小姨让同事汗流浃背" \
|
||||
"18. 标题: 日本女学生在麦当劳被捅致死" \
|
||||
"19. 标题: 女生用绳子编出五脏六腑" \
|
||||
"20. 标题: 带南方女婿吃东北农村大席" \
|
||||
"21. 标题: 俄乌均证实朝军已参与作战" \
|
||||
"22. 标题: 孙颖莎带着三个保镖开心下班" \
|
||||
"23. 标题: 宋佳素颜拍戏好沧桑啊" \
|
||||
"24. 标题: 2岁半宝宝“呲溜滑”超快乐" \
|
||||
"25. 标题: 央视曝光先享后付套路多" \
|
||||
"26. 标题: #阜阳赶大集太香了吧#" \
|
||||
"27. 标题: 孟子义的面具焊在脸上了" \
|
||||
"28. 标题: 福建一高中生被美国藤校录取" \
|
||||
"29. 标题: 2岁社牛女孩跟满屋小朋友搭话" \
|
||||
"30. 标题: 王安宇 人怎么能丢这么大的脸" \
|
||||
"31. 标题: 被挡在村规民约外的“外嫁女”" \
|
||||
"32. 标题: 粉尘爆炸致8死8伤 官方公布调查报告" \
|
||||
"33. 标题: 游客在广东发现一窝6枚恐龙蛋化石" \
|
||||
"34. 标题: 胖东来回应微信小程序的官方店铺" \
|
||||
"35. 标题: 张柏芝把博物馆展品戴在身上" \
|
||||
"36. 标题: 长沙一大桥下浮尸已打捞身份待确认" \
|
||||
"37. 标题: 陈都灵终于演上一整部剧的女妖了" \
|
||||
"38. 标题: 网上下载公开信息发给间谍换钱" \
|
||||
"39. 标题: 7岁异瞳女孩在学校受到同学喜爱" \
|
||||
"40. 标题: 男子面试遭猥亵后发声竟遭网暴" \
|
||||
"41. 标题: 乌女权示威者裸上身破坏纪念雕塑" \
|
||||
"42. 标题: 王宝强喊话甄子丹一起打坏人" \
|
||||
"43. 标题: 记者卧底非法屠宰场内部极度脏乱" \
|
||||
"44. 标题: 印度一教师遭绑架强迫结婚" \
|
||||
"45. 标题: 媒体人:高拉特在中国拿了5亿元" \
|
||||
"46. 标题: 导演回应53岁的于和伟演大学生" \
|
||||
"47. 标题: 山姆销售的床笠甲醛超标被罚" \
|
||||
"48. 标题: 留学回国人才纳入国家统一就业体系" \
|
||||
"49. 标题: 张家界长满了韩国人" \
|
||||
"50. 标题: 圆通快递回应装车工因热射病去世"
|
||||
rsp = xinghuo.get_answer(question)
|
||||
|
||||
print(rsp)
|
||||
|
||||
0
db_info.py
Normal file
0
db_info.py
Normal file
0
group_msg.py
Normal file
0
group_msg.py
Normal file
8
main.py
8
main.py
@@ -47,13 +47,15 @@ def main(chat_type: int):
|
||||
robot.enableReceivingMsg() # 加队列
|
||||
|
||||
# 每天 7 点发送天气预报
|
||||
robot.onEveryTime("07:00", weather_report, robot=robot)
|
||||
# robot.onEveryTime("07:00", weather_report, robot=robot)
|
||||
|
||||
# 每天 7:30 发送新闻
|
||||
robot.onEveryTime("07:30", robot.newsReport)
|
||||
robot.onEveryTime("08:30", robot.newsReport)
|
||||
|
||||
# 每天 16:30 提醒发日报周报月报
|
||||
robot.onEveryTime("16:30", ReportReminder.remind, robot=robot)
|
||||
# robot.onEveryTime("10:30", ReportReminder.remind, robot=robot)
|
||||
# epic
|
||||
robot.onEveryTime("10:30", robot.sendEpicFreeGames)
|
||||
|
||||
# 让机器人一直跑
|
||||
robot.keepRunningAndBlockProcess()
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
chinese_calendar
|
||||
lxml
|
||||
chinese_calendar~=1.10.0
|
||||
lxml~=5.3.0
|
||||
openai>1.0.0
|
||||
pandas
|
||||
pyyaml
|
||||
requests
|
||||
schedule
|
||||
pandas~=2.2.3
|
||||
pyyaml~=6.0.2
|
||||
requests~=2.32.3
|
||||
schedule~=1.2.2
|
||||
pyhandytools
|
||||
sparkdesk-api==1.3.0
|
||||
wcferry==39.2.*
|
||||
websocket
|
||||
pillow
|
||||
jupyter_client
|
||||
zhdate
|
||||
websocket~=0.2.1
|
||||
pillow~=11.0.0
|
||||
jupyter_client~=8.6.3
|
||||
zhdate~=0.1
|
||||
ipykernel
|
||||
google-generativeai
|
||||
zhipuai
|
||||
zhipuai~=2.1.5.20241204
|
||||
|
||||
protobuf~=5.29.1
|
||||
beautifulsoup4~=4.12.3
|
||||
httpx~=0.28.1
|
||||
pyttsx3~=2.98
|
||||
47
robot.py
47
robot.py
@@ -6,6 +6,8 @@ import time
|
||||
import xml.etree.ElementTree as ET
|
||||
from queue import Empty
|
||||
from threading import Thread
|
||||
|
||||
from base.func_epic import is_friday, get_free
|
||||
from base.func_zhipu import ZhiPu
|
||||
|
||||
from wcferry import Wcf, WxMsg
|
||||
@@ -117,7 +119,12 @@ class Robot(Job):
|
||||
rsp = "你@我干嘛?"
|
||||
else: # 接了 ChatGPT,智能回复
|
||||
q = re.sub(r"@.*?[\u2005|\s]", "", msg.content).replace(" ", "")
|
||||
rsp = self.chat.get_answer(q, (msg.roomid if msg.from_group() else msg.sender))
|
||||
if q == "今日百度新闻":
|
||||
self.newsBaiduReport()
|
||||
elif q in ["nbc","cnn","abc","fox","bbc"] :
|
||||
self.newsEnReport(q)
|
||||
else:
|
||||
rsp = self.chat.get_answer(q, (msg.roomid if msg.from_group() else msg.sender))
|
||||
|
||||
if rsp:
|
||||
if msg.from_group():
|
||||
@@ -166,6 +173,8 @@ class Robot(Job):
|
||||
if msg.content == "^更新$":
|
||||
self.config.reload()
|
||||
self.LOG.info("已更新")
|
||||
if msg.content == "今日36氪新闻" :
|
||||
self.newsReport()
|
||||
else:
|
||||
self.toChitchat(msg) # 闲聊
|
||||
|
||||
@@ -260,6 +269,40 @@ class Robot(Job):
|
||||
if not receivers:
|
||||
return
|
||||
|
||||
news = News().get_important_news()
|
||||
news = News().get_36kr_news()
|
||||
for r in receivers:
|
||||
self.sendTextMsg(news, r)
|
||||
|
||||
def newsBaiduReport(self) -> None:
|
||||
receivers = self.config.NEWS
|
||||
if not receivers:
|
||||
return
|
||||
news = News().get_baidu_news()
|
||||
news = f"请根据新闻标题,按照新闻的类型(财经、彩票、房产、股票、家居、教育、科技、社会、时尚、时政、体育、星座、游戏、娱乐)进行分类;内容前加入当前日期和星期几" \
|
||||
"对分类下的内容格式如下:" \
|
||||
"1.#标题1" \
|
||||
"2.#标题2" \
|
||||
"分类使用--号进行分组" + news
|
||||
|
||||
for r in receivers:
|
||||
rsp = self.chat.get_answer(news, r)
|
||||
self.sendTextMsg(rsp, r)
|
||||
|
||||
def newsEnReport(self,website) -> None:
|
||||
receivers = self.config.NEWS
|
||||
if not receivers:
|
||||
return
|
||||
|
||||
news = News().get_eng_news(website)
|
||||
for r in receivers:
|
||||
self.sendTextMsg(news, r)
|
||||
|
||||
def sendEpicFreeGames(self):
|
||||
receivers = self.config.NEWS
|
||||
if not receivers:
|
||||
return
|
||||
if is_friday():
|
||||
games= get_free()
|
||||
for r in receivers:
|
||||
self.sendTextMsg(games, r)
|
||||
|
||||
|
||||
68
task/task_list.py
Normal file
68
task/task_list.py
Normal file
@@ -0,0 +1,68 @@
|
||||
import sqlite3
|
||||
import datetime
|
||||
import schedule
|
||||
import time
|
||||
|
||||
# SQLite数据库文件名
|
||||
DB_FILE = 'tasks.db'
|
||||
|
||||
|
||||
# 初始化数据库
|
||||
def init_db():
|
||||
conn = sqlite3.connect(DB_FILE)
|
||||
c = conn.cursor()
|
||||
c.execute('''CREATE TABLE IF NOT EXISTS tasks
|
||||
(id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
description TEXT NOT NULL,
|
||||
reminder_time TEXT NOT NULL)''')
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
# 添加任务
|
||||
def add_task(description, time_str):
|
||||
conn = sqlite3.connect(DB_FILE)
|
||||
c = conn.cursor()
|
||||
time_obj = datetime.datetime.strptime(time_str, '%Y-%m-%d %H:%M:%S')
|
||||
c.execute("INSERT INTO tasks (description, reminder_time) VALUES (?, ?)",
|
||||
(description, time_obj.isoformat()))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"Task '{description}' added for {time_str}")
|
||||
|
||||
|
||||
# 检查并执行任务
|
||||
def check_tasks():
|
||||
now = datetime.datetime.now().isoformat()
|
||||
conn = sqlite3.connect(DB_FILE)
|
||||
c = conn.cursor()
|
||||
c.execute("SELECT * FROM tasks WHERE reminder_time <= ?", (now,))
|
||||
tasks = c.fetchall()
|
||||
for task in tasks:
|
||||
print(f"Executing task: {task[1]}")
|
||||
# 如果只想执行一次,则删除任务
|
||||
c.execute("DELETE FROM tasks WHERE id = ?", (task[0],))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
# 定时检查任务
|
||||
schedule.every(1).minute.do(check_tasks) # 每分钟检查一次任务
|
||||
|
||||
# 示例使用
|
||||
if __name__ == "__main__":
|
||||
init_db() # 初始化数据库(如果尚未初始化)
|
||||
|
||||
# 添加示例任务(注意:时间应该设置为未来的时间以测试)
|
||||
add_task("Buy groceries", "2024-12-20 14:02:50") # 修改为未来时间进行测试
|
||||
add_task("Attend meeting", "2024-12-20 14:03:50") # 修改为未来时间进行测试
|
||||
|
||||
# 由于我们设置了未来的时间,因此需要使用一个足够长的时间循环来等待任务执行
|
||||
# 在实际应用中,你可能会有一个更优雅的方式来停止循环(例如监听特定事件)
|
||||
print("Starting task scheduler...")
|
||||
try:
|
||||
while True:
|
||||
schedule.run_pending()
|
||||
time.sleep(1) # 等待下一分钟
|
||||
except KeyboardInterrupt:
|
||||
print("Scheduler stopped manually.")
|
||||
BIN
task/tasks.db
Normal file
BIN
task/tasks.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user