-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.py
55 lines (38 loc) · 1.6 KB
/
parser.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
import textract
from bs4 import BeautifulSoup
import markdown
class ResumeParser:
def __init__(self):
pass
def read_pdf(self, filename: str) -> str:
text = textract.process(filename).decode("utf-8")
return text
def read_docx(self, filename: str) -> str:
text = textract.process(filename).decode("utf-8")
return text
def read_doc(self, filename: str) -> str:
text = textract.process(filename).decode("utf-8")
return text
def read_image(self, filename) -> str:
text = textract.process(filename).decode("utf-8") # можно доабавить аргумент language, но надо качать тесеракт textract.process(filename, language="ru").decode("utf-8")
return text
def read_md(self, filename) -> str:
f = open(filename, 'r')
html = markdown.markdown( f.read() )
text = ''.join(BeautifulSoup(html).findAll(text=True))
return text
def parse(self, filename: str) -> str:
if filename.endswith('.pdf'):
return self.read_pdf(filename)
elif filename.endswith('.docx'):
return self.read_docx(filename)
elif filename.endswith('.doc'):
return self.read_doc(filename)
elif filename.endswith('.md'):
return self.read_md(filename)
elif filename.endswith('.txt'):
return Error()
elif filename.endswith('.tex'):
raise Error()
elif filename.endswith('.png') or filename.endswith('.jpg') or filename.endswith('.tiff'):
return self.read_image(filename)