(
*,
user_id: str,
paper: Dict[str, Any],
report_content: str,
report_payload: Dict[str, Any],
doc_url: Optional[str] = None,
doc_token: Optional[str] = None,
)
| 2618 | |
| 2619 | |
| 2620 | def _save_reading_report_markdown( |
| 2621 | *, |
| 2622 | user_id: str, |
| 2623 | paper: Dict[str, Any], |
| 2624 | report_content: str, |
| 2625 | report_payload: Dict[str, Any], |
| 2626 | doc_url: Optional[str] = None, |
| 2627 | doc_token: Optional[str] = None, |
| 2628 | ) -> str: |
| 2629 | target_dir = _resolve_configured_dir( |
| 2630 | "PAPERFLOW_READING_REPORTS_DIR", |
| 2631 | "data/exports", |
| 2632 | paper, |
| 2633 | user_id=user_id, |
| 2634 | category="reading_reports", |
| 2635 | ) |
| 2636 | obsidian_report = target_dir.name.startswith("Deep Reading - ") |
| 2637 | report_path = target_dir / ( |
| 2638 | f"{_paper_title_file_stem(paper)}.md" |
| 2639 | if obsidian_report |
| 2640 | else f"{_paper_file_stem(paper)} - reading-report.md" |
| 2641 | ) |
| 2642 | daily_note_path = _obsidian_daily_note_path(report_path, paper) if obsidian_report else None |
| 2643 | metadata = { |
| 2644 | "user_id": user_id, |
| 2645 | "paper_id": paper.get("id"), |
| 2646 | "arxiv_id": paper.get("arxiv_id"), |
| 2647 | "doi": paper.get("doi"), |
| 2648 | "title": paper.get("title"), |
| 2649 | "institution": report_payload.get("institution") or paper.get("institution") or paper.get("affiliation"), |
| 2650 | "publish_date": paper.get("publish_date"), |
| 2651 | "pdf_path": paper.get("pdf_path"), |
| 2652 | "pdf_url": paper.get("pdf_url"), |
| 2653 | "abs_url": paper.get("abs_url") or paper.get("paper_url") or paper.get("url"), |
| 2654 | "doc_url": doc_url, |
| 2655 | "doc_token": doc_token, |
| 2656 | "generation_provider": report_payload.get("generation_provider"), |
| 2657 | "generation_model": report_payload.get("generation_model"), |
| 2658 | "response_language": report_payload.get("response_language"), |
| 2659 | "report_version": READING_REPORT_OUTPUT_VERSION, |
| 2660 | "daily_note_path": str(daily_note_path) if daily_note_path else None, |
| 2661 | "saved_at": datetime.now().isoformat(timespec="seconds"), |
| 2662 | } |
| 2663 | frontmatter = ["---"] |
| 2664 | for key, value in metadata.items(): |
| 2665 | if value not in (None, "", [], {}): |
| 2666 | frontmatter.append(f"{key}: {json.dumps(value, ensure_ascii=False)}") |
| 2667 | frontmatter.extend(["---", ""]) |
| 2668 | report_path.write_text( |
| 2669 | "\n".join(frontmatter) + report_content.strip() + "\n", |
| 2670 | encoding="utf-8", |
| 2671 | ) |
| 2672 | daily_note_written = _sync_obsidian_daily_note( |
| 2673 | user_id=user_id, |
| 2674 | paper=paper, |
| 2675 | report_payload=report_payload, |
| 2676 | report_path=report_path, |
| 2677 | report_content=report_content, |
no test coverage detected