Mark-MTR ※ AI生成的是代码部分 在班级大屏上安装Python与ClassIsland2,及PutIsland插件; 创造一个py文件; 将下列代码键入此文件: import requests from xml.etree import ElementTree as ET def fetch_and_post_rss(): # 1. 定义需要获取的 RSS 源列表 rss_urls = [ "https://www.chinanews.com.cn/rss/sports.xml", "https://www.chinanews.com.cn/rss/china.xml", "https://www.chinanews.com.cn/rss/world.xml", "https://www.chinanews.com.cn/rss/dxw.xml", "https://www.chinanews.com.cn/rss/finance.xml" ] all_processed_items = [] # 用于存储所有处理后的新闻字符串 for rss_url in rss_urls: try: print(f"正在获取 RSS 源: {rss_url}") response = requests.get(rss_url, timeout=10) response.raise_for_status() # 2. 解析 XML root = ET.fromstring(response.content) # 3. 遍历每个 <item> 节点 for item in root.findall('.//item'): title_elem = item.find('title') description_elem = item.find('description') title_text = title_elem.text.strip() if title_elem is not None and title_elem.text else "[无标题]" description_text = description_elem.text.strip() if description_elem is not None and description_elem.text else "" # 4. 根据正文长度决定拼接内容 if description_text and len(description_text) <= 100: combined_item = f"{title_text} | {description_text}" else: combined_item = title_text all_processed_items.append(combined_item) except requests.exceptions.RequestException as e: print(f"获取 RSS 源 {rss_url} 失败: {e}") continue # 一个源失败,继续处理下一个 except ET.ParseError as e: print(f"解析 RSS 源 {rss_url} 的 XML 失败: {e}") continue # 5. 检查是否有数据,然后拼接并发送 if not all_processed_items: print("未从任何 RSS 源获取到有效新闻条目。") return final_parts = [] for i in range(0, len(all_processed_items), 10): batch = all_processed_items[i:i+10] final_parts.extend(batch) if i + 10 < len(all_processed_items): # 如果不是最后一批,添加声明 final_parts.append("【温馨提醒:记得及时完成学习任务!】") final_combined_string = " | ".join(final_parts) print("处理后的新闻内容预览:") print(final_combined_string) # 6. POST 到本地服务器 (此部分与你原代码一致) post_url = "http://localhost:36000/news" try: post_response = requests.post(post_url, data=final_combined_string.encode('utf-8')) post_response.raise_for_status() print("POST 请求成功") print(f"响应状态码: {post_response.status_code}") except requests.exceptions.RequestException as e: print(f"POST 请求失败: {e}") if __name__ == "__main__": fetch_and_post_rss() 在ClassIsland2 创造一个自动化,并创造一个滚动组件,包含网络文本,token设置为news 设置隐藏规则 ❗️忘记这一步可能会带领至非常严重的后果 创造自动化,在上课且为自习课时运行一次cmd指令,格式为python 你的文件路径与文件名.py 等待同学发出尖锐爆鸣声
Mark-MTR lincube 已在班级下载并安装0.6.1版本,运行LanMountainDesktop.exe后无任何进程启动迹象,卸载后下0.6.0版本,再次运行仍无反应,已尝试使用管理员身份运行仍无反应,系统Win10, 64位