-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandler_process.py
56 lines (42 loc) · 1.51 KB
/
handler_process.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
# -*- coding:utf8 -*-
import os
import docx
import config
import util
from pku_parser import PKUParser
class HandlerProcess(object):
def __init__(self):
self.doc = self.fetch_doc()
self.paper = self.init_paper()
self.parser = self.choose_parser()
def choose_parser(self):
if config.school == "pku":
return PKUParser(self.doc, self.paper)
elif config.school == "thu":
raise Exception("thu is not support")
else:
raise Exception("other school should wait for update")
def save_paper(self):
"""
解析完成后保存论文
"""
paper_path = os.path.join(config.file_path, config.paper_name + config.default_suffix)
self.paper.save(paper_path)
def init_paper(self):
if config.paper_name.endswith(".doc") or config.paper_name.endswith(config.default_suffix):
raise Exception("paper path cannot be end with")
return docx.Document()
def fetch_doc(self):
src = os.path.join(config.file_path, config.file_name)
if src.endswith(".doc"):
dst = src.replace(".doc", config.default_suffix)
util.convert_doc_to_docx(src, dst)
elif src.endswith(config.default_suffix):
dst = src
else:
raise Exception("file must be doc or docx type")
return docx.Document(dst)
def process(self):
self.paper = self.parser.parse()
self.save_paper()
handler_process = HandlerProcess()