Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
206 lines (191 loc) · 6.81 KB
/
Copy pathmain.py
File metadata and controls
206 lines (191 loc) · 6.81 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.10"
# dependencies = [
# "pandas",
# "openpyxl",
# "beautifulsoup4",
# "python-dateutil",
# "pyzotero",
# "arxiv",
# "requests",
# "pyperclip",
# "pyTelegramBotAPI",
# "pymupdf",
# ]
# ///
import argparse
import sys
import os
from report_generator import generate_html
from paper_analyzer import analyze_papers
def main():
banner = "\033[95m" + r"""
_ _ _ _____ _
| | (_) | | __ \ | |
| | _| |_| |__) |___ ___ ___ __ _ _ __ ___| |__
| | | | __| _ // _ \/ __|/ _ \/ _` | '__/ __| '_ \
| |____| | |_| | \ \ __/\__ \ __/ (_| | | | (__| | | |
|______|_|\__|_| \_\___||___/\___|\__,_|_| \___|_| |_|
""" + "\033[0m"
print(banner)
parser = argparse.ArgumentParser(
description="Academic Literature Analysis & Bibliography PDF Compiler Utility"
)
subparsers = parser.add_subparsers(dest="command", required=True, help="Subcommands")
# Subcommand 'generate'
gen_parser = subparsers.add_parser(
"generate",
help="Convert raw bibliography JSON or BIB export to styled HTML report"
)
gen_parser.add_argument(
"--json",
default="privacy.json",
help="Path to bibliography JSON export file (default: privacy.json)"
)
gen_parser.add_argument(
"--bib",
default=None,
help="Path to bibliography.bib file"
)
gen_parser.add_argument(
"--html",
default="bibliography.html",
help="Path to output HTML report file (default: bibliography.html)"
)
# Subcommand 'analyze'
ana_parser = subparsers.add_parser(
"analyze",
help="Query academic APIs, compare authors, and compile LaTeX report to PDF"
)
ana_parser.add_argument(
"--html",
default="bibliography.html",
help="Path to input HTML report file (default: bibliography.html)"
)
ana_parser.add_argument(
"--tex",
default="bibliography.tex",
help="Path to output LaTeX TeX file (default: bibliography.tex)"
)
ana_parser.add_argument(
"--excel",
default=None,
help="Path to top scientists Excel spreadsheet (default: auto-scans directory)"
)
ana_parser.add_argument(
"--template",
default=None,
help="Path to main LaTeX template file (default: report_template.tex)"
)
ana_parser.add_argument(
"--item-template",
default=None,
help="Path to LaTeX item template file (default: paper_item_template.tex)"
)
# Subcommand 'run' (End-to-end pipeline)
run_parser = subparsers.add_parser(
"run",
help="Run the complete pipeline end-to-end: JSON/BIB -> HTML -> TeX & PDF"
)
run_parser.add_argument(
"--json",
default="privacy.json",
help="Path to input bibliography JSON export file (default: privacy.json)"
)
run_parser.add_argument(
"--bib",
default=None,
help="Path to input bibliography.bib file"
)
run_parser.add_argument(
"--html",
default="bibliography.html",
help="Path to intermediate HTML report file (default: bibliography.html)"
)
run_parser.add_argument(
"--tex",
default="bibliography.tex",
help="Path to output LaTeX TeX file (default: bibliography.tex)"
)
run_parser.add_argument(
"--excel",
default=None,
help="Path to top scientists Excel spreadsheet (default: auto-scans directory)"
)
run_parser.add_argument(
"--template",
default=None,
help="Path to main LaTeX template file (default: report_template.tex)"
)
run_parser.add_argument(
"--item-template",
default=None,
help="Path to LaTeX item template file (default: paper_item_template.tex)"
)
run_parser.add_argument(
"--clean",
action="store_true",
help="Remove intermediate HTML and TeX files after successful run"
)
args = parser.parse_args()
try:
if args.command == "generate":
input_path = args.bib if args.bib else args.json
success = generate_html(input_path, args.html)
if not success:
sys.exit(1)
elif args.command == "analyze":
success = analyze_papers(
input_filename=args.html,
output_filename=args.tex,
excel_path=args.excel,
report_template_path=args.template,
paper_item_template_path=args.item_template
)
if not success:
sys.exit(1)
elif args.command == "run":
try:
print(">>> Phase 1/2: Generating HTML Report...")
input_path = args.bib if args.bib else args.json
success = generate_html(input_path, args.html)
if not success:
print("Failed at Phase 1: HTML generation.")
sys.exit(1)
print("\n>>> Phase 2/2: Querying APIs and Compiling to PDF...")
success = analyze_papers(
input_filename=args.html,
output_filename=args.tex,
excel_path=args.excel,
report_template_path=args.template,
paper_item_template_path=args.item_template
)
if not success:
print("Failed at Phase 2: Paper analysis and PDF compilation.")
sys.exit(1)
finally:
if args.clean:
print("\n>>> Cleaning up intermediate files...")
for fpath in [args.html, args.tex]:
if os.path.exists(fpath):
try:
os.remove(fpath)
print(f" Removed: {fpath}")
except Exception as e:
print(f" Warning: Could not remove {fpath}: {e}")
print("\n>>> Pipeline execution completed successfully!")
except KeyboardInterrupt:
print("\n[!] Execution interrupted by user. Exiting gracefully...")
# If interrupted during run and clean is specified, clean up
if args.command == "run" and args.clean:
print(">>> Cleaning up intermediate files...")
for fpath in [args.html, args.tex]:
if os.path.exists(fpath):
try:
os.remove(fpath)
except:
pass
sys.exit(130)
if __name__ == "__main__":
main()