MCPcopy Create free account
hub / github.com/917Dhj/DeepPaperNote / main

Function main

scripts/write_obsidian_note.py:127–208  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

125
126
127def main() -> None:
128 args = parser().parse_args()
129
130 record = maybe_load_json_record(args.input) or {}
131 title = args.title or str(record.get("title", "")).strip()
132 if not title:
133 raise SystemExit("write_obsidian_note.py requires --title or metadata with a title.")
134
135 if args.lint_json:
136 lint = json.loads(Path(args.lint_json).expanduser().resolve().read_text(encoding="utf-8"))
137 if not lint.get("passes_basic_structure", False):
138 raise SystemExit("write_obsidian_note.py refused to write note because basic structure lint failed.")
139 if not lint.get("passes_style_gate", False):
140 raise SystemExit("write_obsidian_note.py refused to write note because style gate failed.")
141 if not lint.get("passes_math_gate", False):
142 raise SystemExit("write_obsidian_note.py refused to write note because math gate failed.")
143 if "passes_figure_gate" in lint and not lint.get("passes_figure_gate", False):
144 raise SystemExit("write_obsidian_note.py refused to write note because figure gate failed.")
145 if "passes_plan_gate" in lint and not lint.get("passes_plan_gate", False):
146 raise SystemExit("write_obsidian_note.py refused to write note because plan gate failed.")
147 if "passes_substantive_content" in lint and not lint.get("passes_substantive_content", False):
148 raise SystemExit("write_obsidian_note.py refused to write note because substantive content gate failed.")
149
150 if args.content_file:
151 note_text = Path(args.content_file).expanduser().resolve().read_text(encoding="utf-8")
152 elif args.content:
153 note_text = args.content
154 elif args.stdin:
155 note_text = sys.stdin.read()
156 else:
157 raise SystemExit("write_obsidian_note.py requires --content-file, --content, or --stdin.")
158
159 config = runtime_config()
160 if args.vault:
161 config["obsidian_vault"] = args.vault
162 resolved_subdir = resolve_domain_subdir(
163 config,
164 title=title,
165 abstract=str(record.get("abstract", "")),
166 subdir=args.subdir,
167 )
168
169 target_path = resolve_obsidian_note_path(
170 config,
171 title=title,
172 subdir=resolved_subdir,
173 filename=args.filename,
174 )
175 ensure_parent(target_path)
176 asset_dir = target_path.parent / args.asset_subdir
177 figure_decisions = maybe_load_json_record(args.figure_decisions) if args.figure_decisions else {}
178 if args.figure_decisions and figure_decisions is None:
179 raise SystemExit(f"Expected JSON object for --figure-decisions: {args.figure_decisions}")
180 materialized_figures = (
181 materialize_insert_decisions(
182 note_text,
183 target_path,
184 figure_decisions,

Callers 1

Calls 9

maybe_load_json_recordFunction · 0.90
runtime_configFunction · 0.90
resolve_domain_subdirFunction · 0.90
ensure_parentFunction · 0.90
resolve_note_output_modeFunction · 0.90
emitFunction · 0.90
parserFunction · 0.70

Tested by

no test coverage detected