WeeklyReportViaAI/main.py

217 lines
17 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import requests
import datetime
import time
import os
from habanero import Crossref
from serpapi import GoogleSearch
# ================= 1. 配置中心 =================
FEISHU_APP_ID = "cli_a9d25c8530785cc8"
FEISHU_APP_SECRET = "5n00X2JtvKoeWmwcPVRKkcDgnoLMoNGb"
SPREADSHEET_TOKEN = "JyyEsR8tYh9Q2rt08v7cogWznJg"
SHEET_ID = "3105e6"
DS_API_KEY = "sk-a8e71892ed7f478eb60319c231f9c3c2"
DS_API_URL = "https://api.deepseek.com/chat/completions"
SERP_API_KEY = "e2778d6230fb7b81584e875344dd5cd38c8c5679f2b0dd4d1fd1cee7a1461a44"
TARGET_KEYWORDS = ["Silicon Photonics", "Laser", "Metasurface", "Optical Fiber"] # TODO
# ================= 2. 核心功能函数 =================
def get_journal_configs():
"""[STEP 1] 从飞书读取期刊配置"""
print("\n--- [STEP 1] 正在读取飞书期刊配置 ---")
try:
auth_url = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"
token_res = requests.post(auth_url, json={"app_id": FEISHU_APP_ID, "app_secret": FEISHU_APP_SECRET}).json()
token = token_res.get("tenant_access_token")
read_url = f"https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/{SPREADSHEET_TOKEN}/values_batch_get"
headers = {"Authorization": f"Bearer {token}"}
res = requests.get(read_url, params={"ranges": f"{SHEET_ID}!A2:C50"}, headers=headers).json()
value_ranges = res.get("data", {}).get("valueRanges", [])
if not value_ranges: return []
rows = value_ranges[0].get("values", [])
configs = []
for r in rows:
if r and len(r) >= 1 and r[0] and str(r[0]).strip():
configs.append({
"name": str(r[0]).strip(),
"issn": str(r[1]).strip() if (len(r) > 1 and r[1]) else None,
"e_issn": str(r[2]).strip() if (len(r) > 2 and r[2]) else None
})
print(f"✅ 成功加载 {len(configs)} 条有效期刊配置")
return configs
except Exception as e:
print(f"❌ 飞书配置读取失败: {e}")
return []
def fetch_dois_crossref(journal_configs):
"""[STEP 2] 通过 Crossref 锁定最近 7 天的论文"""
print(f"\n--- [STEP 2] 正在 Crossref 检索 (最近 7 天) ---")
cr = Crossref(mailto="hextorize@gmail.com")
start_date = (datetime.date.today() - datetime.timedelta(days=7)).strftime("%Y-%m-%d")
tasks = []
for j in journal_configs:
print(f" > 扫描: {j['name']}...", end="", flush=True)
filters = {'from-pub-date': start_date}
target_issn = j['e_issn'] or j['issn']
query_str = " ".join(TARGET_KEYWORDS)
if target_issn:
filters['issn'] = target_issn
else:
query_str = f'"{j["name"]}" ' + query_str
try:
res = cr.works(filter=filters, query=query_str, limit=3, select="title,DOI")
items = res['message'].get('items', [])
print(f" 找到 {len(items)}")
for art in items:
tasks.append({
"title_en": art['title'][0] if art.get('title') else "No Title",
"doi": art['DOI'],
"journal": j['name']
})
except:
print(" 跳过")
return tasks
def enrich_content_serpapi(tasks):
"""[STEP 3] 利用 SerpApi 提取 Google Scholar 片段"""
print(f"\n--- [STEP 3] 正在通过 SerpApi 提取核心内容 ---")
for i, task in enumerate(tasks):
print(f" [{i + 1}/{len(tasks)}] 检索 DOI: {task['doi']}...", end="", flush=True)
try:
search = GoogleSearch({
"engine": "google_scholar",
"q": f"DOI:{task['doi']}",
"api_key": SERP_API_KEY,
"hl": "en"
})
results = search.get_dict().get("organic_results", [])
task['snippet_en'] = results[0].get("snippet",
"No abstract snippet available.") if results else "No content found."
print(" [OK]")
except Exception as e:
task['snippet_en'] = f"Search Error: {e}"
print(" [Error]")
time.sleep(0.6)
return tasks
def summarize_with_ds(tasks):
"""[STEP 4] 调用 DeepSeek 进行处理"""
print(f"\n--- [STEP 4] 正在请求 DeepSeek 处理内容 ---")
headers = {"Authorization": f"Bearer {DS_API_KEY}", "Content-Type": "application/json"}
for i, task in enumerate(tasks):
print(f" > 处理第 {i + 1} 篇...", end="", flush=True)
prompt = (f"你是一个光学专家。请翻译以下论文标题和摘要为中文并总结核心创新点200字内\n"
f"标题: {task['title_en']}\n摘要: {task['snippet_en']}\n"
f"格式要求:\n中文标题xxx\n中文摘要xxx\nAI总结xxx")
payload = {
"model": "deepseek-chat",
"messages": [{"role": "system", "content": "你是一个严谨的科研助手。"}, {"role": "user", "content": prompt}]
}
try:
res = requests.post(DS_API_URL, json=payload, headers=headers, timeout=30).json()
content = res['choices'][0]['message']['content'].strip()
# 解析 DeepSeek 返回的格式
for line in content.split('\n'):
if "中文标题:" in line: task['title_zh'] = line.split("", 1)[1].strip()
if "中文摘要:" in line: task['snippet_zh'] = line.split("", 1)[1].strip()
if "AI总结" in line: task['summary_zh'] = line.split("", 1)[1].strip()
print(" [完成]")
except:
print(" [失败]")
return tasks
def save_to_markdown(tasks):
"""[STEP 5] 保存为 Markdown 报告"""
print(f"\n--- [STEP 5] 正在生成 Markdown 报告 ---")
today_str = datetime.date.today().strftime("%Y-%m-%d")
file_name = f"{today_str}周报.md"
with open(file_name, "w", encoding="utf-8") as f:
f.write(f"# 光学行业学术动态周报 ({today_str})\n\n")
f.write("---\n\n")
for idx, task in enumerate(tasks):
f.write(f"### {idx + 1}. {task.get('title_zh', 'N/A')}\n\n")
f.write(f"**期刊**: {task['journal']} \n")
f.write(f"**DOI**: [{task['doi']}](https://doi.org/{task['doi']})\n\n")
f.write(f"#### 【标题】\n")
f.write(f"- **中文**: {task.get('title_zh', 'N/A')}\n")
f.write(f"- **英文**: {task['title_en']}\n\n")
f.write(f"#### 【摘要原文】\n")
f.write(f"> *{task.get('snippet_en', 'N/A')}*\n\n")
f.write(f"#### 【摘要翻译】\n")
f.write(f"> {task.get('snippet_zh', 'N/A')}\n\n") # 修正:此处已添加中文摘要
f.write(f"#### 【AI 深度总结】\n")
f.write(f"{task.get('summary_zh', 'N/A')}\n\n")
f.write("---\n\n")
print(f"✅ Markdown 周报已保存: {os.path.abspath(file_name)}")
# ================= 3. 执行入口 =================
if __name__ == "__main__":
final_reports = [{'doi': '10.1038/s41467-025-68011-w', 'journal': 'Nature Communications', 'snippet_en': 'Ionic thermoelectric (i-TE) have become promising candidate for harvesting low-grade thermal energy. However, the development of n-type i-TE materials still lag far behind their p-type counterparts, which impedes the application. Herein, engineering a liquid crystal elastomer (LCE) from side-chain to main-chain structure, just swollen with single LiBF4 or EMIM TFSI, enables the largest adjustable p-n (28.8 ~ 27.4 mV K1) span among current homologous materials below 30% RH. These high n- and p-type performance further ensure the successful integration of a homogeneous π-type fiber-shaped i-TE capacitor, where three p/n pairs yield an output voltage of 402.5 mV under a tiny temperature difference of 2.5 K. The areal energy density of per n-type fiber reaches 8.1 mJ m2. More importantly, the i-TE materials also exhibit excellent stability under loadings of cyclic stretching, long-term testing, or temperature-controlled cycling, highlighting its potential for efficient thermal-charge energy storage in flexible electronics and smart wearables.', 'snippet_zh': '离子热电i-TE材料已成为收集低品位热能的有前景候选者。然而n型i-TE材料的发展仍远落后于p型材料限制了其应用。本文通过将液晶弹性体LCE从侧链结构工程化为主链结构并仅溶胀单一LiBF₄或EMIM TFSI电解质实现了当前同系材料中在30%相对湿度以下最大的可调p-n跨度28.8 ~ 27.4 mV K⁻¹。这种高性能的n型和p型材料进一步确保了均匀π型纤维状i-TE电容器的成功集成其中三对p/n单元在2.5 K的微小温差下产生402.5 mV的输出电压。每根n型纤维的面能量密度达到8.1 mJ m⁻²。更重要的是该i-TE材料在循环拉伸、长期测试或温控循环负载下均表现出优异的稳定性凸显了其在柔性电子和智能穿戴设备中高效热-电荷能量存储的潜力。', 'summary_zh': '本研究通过将液晶弹性体从侧链重构为主链结构并溶胀单一电解质开发出具有宽范围可调p-n型热电性能28.8 ~ 27.4 mV K⁻¹的新型离子热电材料。基于此材料首次构建了均匀π型纤维状离子热电电容器在2.5 K微小温差下实现402.5 mV输出电压且n型纤维面能量密度达8.1 mJ m⁻²。该材料在机械拉伸和温度循环中表现优异稳定性为柔性电子器件提供了高效热能收集与存储新方案。', 'title_en': 'Engineering liquid crystal elastomer unlocks high thermopower for fiber-shaped ionic thermoelectric capacitors', 'title_zh': '工程化液晶弹性体解锁纤维状离子热电电容器的高热电势'}, {'doi': '10.1038/s41467-025-68148-8', 'journal': 'Nature Communications', 'snippet_en': 'Photoacoustic microscopy (PAM) has been widely used in biomedical studies to provide high-resolution 3D anatomical, functional, and molecular images of living subjects. While handheld PAM systems have been proposed to extend its applicability, it has proved challenging to achieve a compact device that combines fast imaging with high spatial resolution and signal to noise ratio. Here we demonstrate a handheld PAM probe integrating a fiber scanner and high-frequency transparent ultrasound transducer (TUT), called hPAM-TUT. The compact system (measuring 17 mm in diameter, with a 90 mm long rigid body) achieves high lateral and axial resolutions (7 and 47 μm, respectively), has a 2.6 mm diameter field of view, and delivers a single volumetric image in 1.5 s. In living rats, we used hPAM-TUT to visualize various abdominal organs, and in mice we used it to observe epinephrine-induced vascular changes and image the anatomy and functioning of lymphatic vessels after injection of Evans blue dye. Additionally, we successfully delineated murine vascular networks in early metastatic tumors. This handheld PAM probe shows promise for both clinical and research applications in such fields as dermatology, oncology, and intraoperative imaging.', 'snippet_zh': '光声显微镜PAM已广泛应用于生物医学研究能够为活体提供高分辨率的三维解剖、功能及分子图像。尽管已有手持式PAM系统被提出以拓展其应用范围但实现兼具快速成像、高空间分辨率和高信噪比的紧凑型设备仍具挑战。本文展示了一种集成光纤扫描器与高频透明超声换能器TUT的手持式PAM探头称为hPAM-TUT。该紧凑系统直径17毫米刚性主体长90毫米实现了较高的横向与轴向分辨率分别为7微米和47微米具备2.6毫米直径的视场并能在1.5秒内完成单次三维成像。在活体大鼠中我们利用hPAM-TUT观察了多种腹部器官在小鼠中实现了肾上腺素诱导的血管变化观测并通过注射伊文思蓝染料对淋巴管的解剖结构与功能进行了成像。此外我们成功勾勒了早期转移性肿瘤内的小鼠血管网络。这种手持式PAM探头在皮肤病学、肿瘤学及术中成像等领域的临床与研究应用中展现出广阔前景。', 'summary_zh': '本研究创新性地将高频透明超声换能器TUT与光纤扫描器集成于一体研制出超紧凑手持式光声显微探头hPAM-TUT。其核心突破在于解决了传统手持PAM设备难以兼顾小型化、高分辨率横向7μm/轴向47μm、快速三维成像1.5秒/体积与大视场2.6mm)的技术矛盾,并通过活体动物实验验证了在多器官成像、动态血管监测及肿瘤微血管可视化等方面的应用潜力,为临床床旁检测和术中实时成像提供了新型工具。', 'title_en': 'A handheld photoacoustic microscopic probe integrating a transparent ultrasound transducer and a fiber scanner', 'title_zh': '一种集成透明超声换能器和光纤扫描器的手持式光声显微探头'}, {'doi': '10.1038/s41467-025-67954-4', 'journal': 'Nature Communications', 'snippet_en': 'Quartz optical fibers are brittle, difficult to repair, and lack reconfigurability, limiting their adaptability in underwater communication. To overcome these impediments, here we show reconfigurable all-liquid optical fibers (RAOFs) produced by structured liquid, tuned by the interfacial assembly and jamming of nanoparticle surfactants at the water-oil interface (interfacial tension <10 mN m-1, refractive index contrast of 0.083). These RAOFs combine the structural stability of the interfacial assemblies with the inherent flexibility of liquids. They support real-time communication on an Ethernet platform (up to 1 Gbps), providing a practical alternative to conventional optical fibers for optical interconnects. Their liquid nature enables broken fibers to be repaired rapidly by a coalescence process. Their softness affords on-demand reconfigurability that enables in-situ fabrication of reconfigurable optical fibers and dynamic manipulation of signal transmission. RAOFs provide a versatile, self-healing, and resilient solution for optical communication systems in dynamic environments.', 'snippet_zh': '石英光纤脆性高、难以修复且缺乏可重构性限制了其在水下通信中的适应性。为克服这些缺陷本研究展示了一种通过结构化液体构建的可重构全液体光学纤维RAOFs其通过纳米颗粒表面活性剂在水-油界面(界面张力<10 mN m⁻¹折射率对比度0.083的界面组装与阻塞效应实现调控。这些RAOFs兼具界面组装的结构稳定性和液体的固有柔性可在以太网平台上支持实时通信最高1 Gbps为光互连提供了传统光纤的实用替代方案。其液体特性使断裂纤维能通过融合过程快速修复而柔软性则赋予其按需重构能力实现可重构光纤的原位制备和信号传输的动态调控。RAOFs为动态环境中的光通信系统提供了一种多功能、自修复且适应性强的解决方案。', 'summary_zh': '本研究创新性地利用纳米颗粒界面组装技术,构建了具有结构稳定性和液体柔性的全液体光纤。其核心突破在于:通过低界面张力液体界面调控,实现了光纤的可重构性、自修复能力和动态信号操控,并在以太网环境中达成千兆级实时通信,为动态环境光通信提供了传统石英光纤无法兼具的柔性、可修复与自适应传输新路径。', 'title_en': 'Structured liquid-based reconfigurable all-liquid optical fibers', 'title_zh': '基于结构化液体的可重构全液体光学纤维'}]
for r in final_reports:
print(f"\n{r['journal']}")
print(f"英文标题:{r['title_en']}")
print(f"中文标题:{r.get('title_zh', 'N/A')}")
print(f"英文摘要:{r.get('snippet_en', 'N/A')}")
print(f"中文摘要:{r.get('snippet_zh', 'N/A')}") # 终端打印摘要翻译
print(f"AI 总结:{r.get('summary_zh', 'N/A')}")
print(f"链接: https://doi.org/{r['doi']}")
print("-" * 40)
# 生成 Markdown 文件
save_to_markdown(final_reports)
# start_time = time.time()
# configs = get_journal_configs()
# if configs:
# paper_tasks = fetch_dois_crossref(configs)
# if paper_tasks:
# enriched = enrich_content_serpapi(paper_tasks)
# final_reports = summarize_with_ds(enriched)
#
# # 打印汇总预览 (所有原文/翻译/总结都会在这里显示)
# print("\n" + "=" * 60)
# print(f"📊 最终简报汇总预览 - {datetime.date.today()}")
# print("=" * 60)
# for r in final_reports:
# print(f"\n【{r['journal']}】")
# print(f"英文标题:{r['title_en']}")
# print(f"中文标题:{r.get('title_zh', 'N/A')}")
# print(f"英文摘要:{r.get('snippet_en', 'N/A')}")
# print(f"中文摘要:{r.get('snippet_zh', 'N/A')}") # 终端打印摘要翻译
# print(f"AI 总结:{r.get('summary_zh', 'N/A')}")
# print(f"链接: https://doi.org/{r['doi']}")
# print("-" * 40)
#
# # 生成 Markdown 文件
# save_to_markdown(final_reports)
# else:
# print("\n📭 无新发现。")
# print(f"\n✨ 总耗时: {round(time.time() - start_time, 2)}s")