-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathserver.py
More file actions
37 lines (30 loc) · 819 Bytes
/
server.py
File metadata and controls
37 lines (30 loc) · 819 Bytes
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
from flask import Flask, request
import pdfplumber
app = Flask(__name__)
"""
Server receives post request from Client with URL content.
"""
@app.route('/attachment', methods=['POST'])
def saves_content():
data = request.get_data()
save_to_disk(data)
extract_pdf_to_txt('attachment.pdf')
return "Received"
"""
Writes attachment content and extracted text from PDF to disk
URL's can be found in README
"""
def save_to_disk(data):
with open("attachment.pdf", 'wb') as f:
f.write(data)
'''
Extracts text from PDF
'''
def extract_pdf_to_txt(pdf):
with pdfplumber.open('attachment.pdf') as pdf:
file = pdf.pages
with open('attachment.txt', 'w') as f:
for page in file:
f.write(page.extract_text())
if __name__ == "__main__":
app.run()