-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
56 lines (44 loc) · 1.73 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import argparse
from pathlib import Path
import re
from scripts.arxiv_fetcher import ArxivPaper
from scripts.pdf_processor import PDFProcessor
from scripts.note_creator import create_obsidian_note
def main():
parser = argparse.ArgumentParser(description='Convert arXiv paper to Obsidian note')
parser.add_argument('arxiv_id', help='arXiv paper ID (e.g., 2101.12345)')
parser.add_argument('--output', '-o', help='Output directory', default='.')
args = parser.parse_args()
try:
# Create output directory
output_path = Path(args.output)
output_path.mkdir(parents=True, exist_ok=True)
# Fetch and download paper
print(f"Fetching paper {args.arxiv_id} from arXiv...")
paper = ArxivPaper(args.arxiv_id)
metadata = paper.fetch_metadata()
pdf_path = paper.download_pdf(output_path)
if not pdf_path:
raise Exception("Failed to download PDF")
# Process PDF content
print("Processing PDF content...")
pdf_processor = PDFProcessor(pdf_path)
sections = pdf_processor.identify_sections()
# Create note
print("Creating Obsidian note...")
note_content = create_obsidian_note(metadata, sections)
# Save note
safe_title = re.sub(r'[<>:"/\\|?*]', '', metadata['title'])
safe_title = safe_title.replace(' ', '_')
note_file = output_path / f"{safe_title}.md"
with open(note_file, 'w', encoding='utf-8') as f:
f.write(note_content)
print(f"Successfully created:")
print(f"- Note: {note_file}")
print(f"- PDF: {pdf_path}")
except Exception as e:
print(f"Error: {str(e)}")
return 1
return 0
if __name__ == "__main__":
main()