版本:未加入题库版本最后一版
This commit is contained in:
@@ -52,13 +52,22 @@ def message_task_json(prompt, content):
|
|||||||
|
|
||||||
|
|
||||||
def game_question_json(question):
|
def game_question_json(question):
|
||||||
prompt = """请根据以下要求,随机生成一个问题,确保每次提问都涉及不同的领域,并且每个问题都互不相关:
|
prompt = """
|
||||||
本次的问题请充满乐趣,请确保问题足够简洁且容易理解,适合百科类知识问答。
|
请根据以下要求,随机生成一个问题,确保每次提问涉及不同领域,且不重复:
|
||||||
每个问题都应当独立,问题之间不应具有连贯性或延续性。
|
1. 每个问题应该覆盖以下任意领域:近现代史、战争与政治、文化遗产与考古学、进化论、动植物学、基因与遗传学、生态学、有机化学、无机化学、生物化学、环境化学、人文地理、自然地理、地质学、气候变化、古典文学、现代文学、小说与戏剧、诗歌与散文、美术、音乐、戏剧与舞蹈、电影与媒体、西方哲学、东方哲学、道德与伦理学、逻辑与认识论、人类学、心理学、政治学、经济学、编程语言、人工智能、数据科学、网络与安全、机械工程、电气工程、化学工程、土木工程、解剖学、生理学、临床医学、药学与护理、球类运动、奥林匹克运动、运动心理学、健身与营养、世界宗教、神话与民间故事、宗教哲学、语法与词汇、语言习得、方言与语言变异、宏观经济学、微观经济学、国际贸易、金融与投资、民法与刑法、国际法、知识产权法、环境法。
|
||||||
避免重复提问或相似问题,确保每个问题都是全新的。
|
2. 问题应简洁,具有一定难度,易于理解且充满乐趣,适合百科类知识问答。
|
||||||
,问题需要有一定的难度,回答完毕之后用户能有所收获,并且对问题进行打分,同时根据问题难度告知答对之后给多少分(1-10)请只返回JSON格式的内容:
|
3. 每个问题应独立,且问题之间无连贯性或延续性。
|
||||||
格式要求如下(请不要加上markdown 的符号):{\"question\": \"哪个国家最早将玫瑰与爱情联系起来?\", \"score\":\"1\", \"answer\": \"波斯\",\"description\":\"描述问题答案的原因\"}
|
4. 避免重复提问或产生相似的问题,确保问题新颖。
|
||||||
"""
|
5. 对于每个问题,提供难度评分(1-10分)。在问题答对后,用户可以根据难度给出相应的分数。
|
||||||
|
|
||||||
|
输出格式要求如下(仅返回JSON格式,确保不添加多余的符号):
|
||||||
|
{
|
||||||
|
"question": "哪个国家最早将玫瑰与爱情联系起来?",
|
||||||
|
"score": "1",
|
||||||
|
"answer": "波斯",
|
||||||
|
"description": "波斯文化中,玫瑰被广泛认为是象征爱情的花卉,其象征意义逐渐传入西方。"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
|
||||||
return message_task_json(prompt, question)
|
return message_task_json(prompt, question)
|
||||||
|
|
||||||
@@ -69,5 +78,5 @@ def game_answer_json(answer):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(game_question_json('请从不同的学科领域(历史学:古代历史、近现代史、战争与政治、文化遗产与考古学;生物学:进化论、动植物学、基因与遗传学、生态学;化学:有机化学、无机化学、生物化学、环境化学;地理学:人文地理、自然地理、地质学、气候变化;文学:古典文学、现代文学、小说与戏剧、诗歌与散文;艺术:美术、音乐、戏剧与舞蹈、电影与媒体;哲学:西方哲学、东方哲学、道德与伦理学、逻辑与认识论;社会学:人类学、心理学、政治学、经济学;计算机科学:编程语言、人工智能、数据科学、网络与安全;工程学:机械工程、电气工程、化学工程、土木工程;医学:解剖学、生理学、临床医学、药学与护理;体育:球类运动、奥林匹克运动、运动心理学、健身与营养;宗教与神话:世界宗教、神话与民间故事、宗教哲学;语言学:语法与词汇、语言习得、方言与语言变异;经济学:宏观经济学、微观经济学、国际贸易、金融与投资;法律:民法与刑法、国际法、知识产权法、环境法)生成一个全新问题。'))
|
print(game_question_json('请出题!'))
|
||||||
# print(game_answer_json('question:哪个国家的节日与裸体狂欢有关?,answer:古罗马,top_score:3'))
|
# print(game_answer_json('question:哪个国家的节日与裸体狂欢有关?,answer:古罗马,top_score:3'))
|
||||||
|
|||||||
@@ -14,10 +14,12 @@ db_config = {
|
|||||||
'cursorclass': pymysql.cursors.DictCursor
|
'cursorclass': pymysql.cursors.DictCursor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# 连接数据库
|
# 连接数据库
|
||||||
def get_db_connection():
|
def get_db_connection():
|
||||||
return pymysql.connect(**db_config)
|
return pymysql.connect(**db_config)
|
||||||
|
|
||||||
|
|
||||||
# 添加群聊
|
# 添加群聊
|
||||||
def add_group(group_id, player_id):
|
def add_group(group_id, player_id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -35,6 +37,7 @@ def add_group(group_id, player_id):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 获取所有群聊ID
|
# 获取所有群聊ID
|
||||||
def get_group_ids():
|
def get_group_ids():
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -46,6 +49,7 @@ def get_group_ids():
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 确保游戏启动(自动初始化群聊和玩家)
|
# 确保游戏启动(自动初始化群聊和玩家)
|
||||||
def ensure_game_started(group_id, player_id, player_name="未知玩家"):
|
def ensure_game_started(group_id, player_id, player_name="未知玩家"):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -79,6 +83,7 @@ def ensure_game_started(group_id, player_id, player_name="未知玩家"):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 随机分配任务
|
# 随机分配任务
|
||||||
def assign_random_task(group_id, player_id=None):
|
def assign_random_task(group_id, player_id=None):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -147,6 +152,7 @@ def assign_random_task(group_id, player_id=None):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 提交答案并计分
|
# 提交答案并计分
|
||||||
def submit_answer(group_id, player_id, task_id, answer):
|
def submit_answer(group_id, player_id, task_id, answer):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -277,6 +283,7 @@ def submit_answer(group_id, player_id, task_id, answer):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 显示排行榜
|
# 显示排行榜
|
||||||
def show_rank(group_id, player_id):
|
def show_rank(group_id, player_id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -301,6 +308,7 @@ def show_rank(group_id, player_id):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 显示当前活跃任务
|
# 显示当前活跃任务
|
||||||
def show_active_tasks(group_id, player_id):
|
def show_active_tasks(group_id, player_id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -331,6 +339,7 @@ def show_active_tasks(group_id, player_id):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 列举所有未完成任务
|
# 列举所有未完成任务
|
||||||
def list_uncompleted_tasks(group_id, player_id):
|
def list_uncompleted_tasks(group_id, player_id):
|
||||||
conn = get_db_connection()
|
conn = get_db_connection()
|
||||||
@@ -361,6 +370,7 @@ def list_uncompleted_tasks(group_id, player_id):
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
# 定时任务:整点触发,排除23:00-08:00
|
# 定时任务:整点触发,排除23:00-08:00
|
||||||
def run_random_task_assignment(group_id):
|
def run_random_task_assignment(group_id):
|
||||||
current_hour = datetime.now().hour
|
current_hour = datetime.now().hour
|
||||||
@@ -370,6 +380,7 @@ def run_random_task_assignment(group_id):
|
|||||||
result = assign_random_task(group_id)
|
result = assign_random_task(group_id)
|
||||||
print(f"{datetime.now()} {result}")
|
print(f"{datetime.now()} {result}")
|
||||||
|
|
||||||
|
|
||||||
# 处理群聊消息
|
# 处理群聊消息
|
||||||
def game_process_message(group_id, player_id, message, player_name="未知玩家"):
|
def game_process_message(group_id, player_id, message, player_name="未知玩家"):
|
||||||
# 自动初始化群聊和玩家
|
# 自动初始化群聊和玩家
|
||||||
@@ -436,12 +447,14 @@ def game_process_message(group_id, player_id, message, player_name="未知玩家
|
|||||||
f"🎀 /r - 查看排行榜"
|
f"🎀 /r - 查看排行榜"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 设置定时任务
|
# 设置定时任务
|
||||||
def setup_schedule():
|
def setup_schedule():
|
||||||
group_ids = get_group_ids()
|
group_ids = get_group_ids()
|
||||||
for gid in group_ids:
|
for gid in group_ids:
|
||||||
run_random_task_assignment(group_id=gid)
|
run_random_task_assignment(group_id=gid)
|
||||||
|
|
||||||
|
|
||||||
# 主程序
|
# 主程序
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 测试用例
|
# 测试用例
|
||||||
|
|||||||
49
xiuren/xiuren_dl.py
Normal file
49
xiuren/xiuren_dl.py
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import requests
|
||||||
|
from lxml import etree
|
||||||
|
import os
|
||||||
|
|
||||||
|
# 设置目标URL和请求头
|
||||||
|
url = "https://www.xiurenwang.cc/bang?f=7"
|
||||||
|
headers = {
|
||||||
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
|
||||||
|
"Referer": "https://www.xiurenwang.cc/"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 发送请求获取网页内容
|
||||||
|
response = requests.get(url, headers=headers)
|
||||||
|
response.encoding = "utf-8" # 确保正确解码
|
||||||
|
|
||||||
|
# 解析HTML
|
||||||
|
html = etree.HTML(response.text)
|
||||||
|
|
||||||
|
# 提取图片链接和标题(假设最新图片在列表页面中)
|
||||||
|
image_items = html.xpath('//div[@class="list"]/li/a[@class="img"]/@href')
|
||||||
|
titles = html.xpath('//div[@class="tit"]/a/text()')
|
||||||
|
|
||||||
|
# 创建保存图片的文件夹
|
||||||
|
save_dir = "./xiuren_images"
|
||||||
|
if not os.path.exists(save_dir):
|
||||||
|
os.makedirs(save_dir)
|
||||||
|
|
||||||
|
# 只获取最新的一个条目(假设第一个是最新的)
|
||||||
|
if image_items:
|
||||||
|
latest_url = "https://www.xiurenwang.cc" + image_items[0] # 拼接详情页URL
|
||||||
|
latest_title = titles[0] if titles else "latest_image"
|
||||||
|
|
||||||
|
# 访问详情页获取图片
|
||||||
|
detail_response = requests.get(latest_url, headers=headers)
|
||||||
|
detail_html = etree.HTML(detail_response.text)
|
||||||
|
image_urls = detail_html.xpath('//div[@id="image"]/a/@href')
|
||||||
|
|
||||||
|
# 下载图片
|
||||||
|
for idx, img_url in enumerate(image_urls):
|
||||||
|
img_response = requests.get(img_url, headers=headers)
|
||||||
|
img_name = f"{latest_title}_{idx + 1}.jpg"
|
||||||
|
img_path = os.path.join(save_dir, img_name.replace('/', '_')) # 避免文件名中的斜杠
|
||||||
|
with open(img_path, "wb") as f:
|
||||||
|
f.write(img_response.content)
|
||||||
|
print(f"已下载: {img_path}")
|
||||||
|
else:
|
||||||
|
print("未找到图片链接,可能需要调整XPath或检查网站结构。")
|
||||||
|
|
||||||
|
print("最新图片下载完成!")
|
||||||
Reference in New Issue
Block a user