Files
note_sync/大模型/deepseek/_scripts/add_papers.py
T

61 lines
2.2 KiB
Python

"""Append newly discovered papers to the plan without disturbing existing numbering.
Usage: python add_papers.py <plan.json> <verified_extra.json> <base_dir>
"""
import json
import os
import shutil
import sys
# explicit stems so existing numbered files are never renumbered
ASSIGN = {
'2310.16818': ('05-多模态', '08-DreamCraft3D-2310.16818', '多模态'),
'2408.15664': ('07-架构', '04-Aux-Loss-Free-Load-Balancing-2408.15664', '架构'),
'2411.07975': ('05-多模态', '07-JanusFlow-2411.07975', '多模态'),
'2502.07316': ('02-代码模型', '03-CodeIO-2502.07316', '代码模型'),
'2502.11089': ('07-架构', '03-NSA-原生稀疏注意力-2502.11089', '架构'),
}
def main():
plan_path, ver_path, base = sys.argv[1], sys.argv[2], sys.argv[3]
plan = json.load(open(plan_path, encoding='utf-8'))
have = {p['id'] for p in plan}
extra = json.load(open(ver_path, encoding='utf-8'))
added = []
for r in extra:
if not r.get('ok') or r['id'] in have:
continue
d, stem, cat = ASSIGN[r['id']]
outdir = os.path.join(base, d)
os.makedirs(outdir, exist_ok=True)
src = os.path.join(base, 'pdf', r['id'] + '.pdf')
dst = os.path.join(outdir, stem + '.pdf')
if os.path.exists(src) and not os.path.exists(dst):
shutil.move(src, dst)
plan.append({
'id': r['id'],
'title': r.get('title', ''),
'authors': r.get('authors', ''),
'abstract': r.get('abstract', ''),
'dateline': r.get('dateline', ''),
'date': r.get('dateline', ''),
'comments': r.get('comments', ''),
'category': cat,
'dir': d,
'stem': stem,
'pdf_path': os.path.join(d, stem + '.pdf'),
'md_path': os.path.join(d, stem + '.md'),
'pdf_url': 'https://arxiv.org/pdf/' + r['id'],
'abs_url': 'https://arxiv.org/abs/' + r['id'],
})
added.append((r['id'], d, stem, r.get('title', '')))
json.dump(plan, open(plan_path, 'w', encoding='utf-8'), ensure_ascii=False, indent=1)
for a in added:
print('added', a)
print('total', len(plan))
if __name__ == '__main__':
main()