From f2a7a8d0007f043917e7721c351aeae39c787ef7 Mon Sep 17 00:00:00 2001 From: nglk Date: Mon, 21 Mar 2022 13:19:54 +0100 Subject: [PATCH] half way setting up the app.py for downloading file from url --- __pycache__/app.cpython-37.pyc | Bin 1832 -> 1634 bytes app.py | 60 ++++++++++++++++++++------------- templates/.results.html.swp | Bin 0 -> 1024 bytes templates/results.html | 8 +++-- 4 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 templates/.results.html.swp diff --git a/__pycache__/app.cpython-37.pyc b/__pycache__/app.cpython-37.pyc index 2439b5f5db38fb152bb6e4fffc09f3ceffb72fb4..2aec24987f828dbd528c5a14e6ee19a685db7a32 100644 GIT binary patch delta 533 zcmYjNv2GJV5Z$@kbB@#9IgW!J8xzYIA)JDUE>fTgf>2QyiNek4U^a=5J72W777}tq z;k1bqZ9@figWx|9KS1XSQBWb#Q!(pMWLG;o`)207+4&s)^uxU%@EEObw)3*@UxeSD zVj$|t28It9-AydxDpn3HTsyNwBe{W9Tt8(~n8Kii*RgiW1~)|w>#r^OThwQpa|R6I zIqPlc7JT*JdWDMB@YVJ)9_Sx%{~aeSht4B9MW2jf2_R7U6Y?yy8tjBk7`^O-&m2`s zR?uz`GPh1(!e;IS<^W7xQy%gOL+8wzlANkwsMeMD8OmFk9Cr#_pC8PWN zvCWC)BfrDHFxk=H`QGhKiZJe39&lI(4_2Erj;lM6UA^z*`wQ2!F^V%GJBD&;Zjra} z<223Rh|4}-5K@?tF>pa{nYbH8Sv(v?QLim)`j7Lz-6DATOL_Nyg5ixK*)V~o{#5F; YyT)DC+j2a*qIoH-f0Z6OyRPHHKSx@60{{R3 delta 738 zcmYjOO>fgc5Zzs`6W4K^q)nTqpW)C{k)RcvK!QsVQV*yXBo5_ZnU34WapG#d1ra%_ zM0za}@&ySAr56N$fM0<6BYZ+|?JwZOOe&#zG_%id-p=#LznyQcyHhUP44=x&hp%7R zAKk0npdK{BMJPXJcrJkp6{sEws9lJl87{*t%$>6_AM^bcsKfj@+g}Y9V4)|}b$)B(|C zBbKtT021}jQH8zRs+6hsx=4yKM`Ycg5!W-JJt=7?ET2K4$x?nPMj~YsHx-vOpfafv z8W||5O=h7uW#>`@ESR|vBbmyu4mOm)!6;uyT+1DqdLF8JVaz_zinTpe!F6(Z*o}gr zvlq7rv`&1bb2hBvdlE!J=|BfC?I7 z`s=75IgNC(b*%eQhpRf8bQ-EiUWI<3k7LM9vPzUhPMOp&PF0j!#18y^kUM@9#cu=f zh*9*5a}g)GJn^$P#&Y)AcxDw;jczYye~h-fZ;>^LzcaOwmF3QZyVzyY7B;uI&28i6 zbP?CNEp6^#NG_&f8PZmpSt8>{YLTXH{4Z@nO)R^Z34Jibfm0^8Jg@I}2cFkiS4&yP w{IuS}wsNSDJqc(X&r_?!t!2N=JL{VSX<}}u)4?sPscAcF6`q*)EYsru0FV)|KL7v# diff --git a/app.py b/app.py index 9357173..b386d7d 100644 --- a/app.py +++ b/app.py @@ -20,7 +20,7 @@ app.config['BASIC_AUTH_PASSWORD'] = 'tentacles' basic_auth = BasicAuth(app) -app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +app.config['UPLOAD_FOLDER'] = "static/pdf" @app.route('/', methods=['GET', 'POST']) @@ -28,34 +28,48 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER def run_script(): # the code below was made in case I was using a button upload but now I use the field input so this has to be uploaded and then transformed if request.method == 'POST': + # download PDF from url + file = request.form['file'] + if file: + uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], file) + file.save(uploadfilepath) + return redirect(url_for('uploaded_file',file=file)) + # url = request.form['url'] + #if not url: + # flash('Url is required!') + # else: + # messages.append({'url': url}) + # return redirect(url_for('index')) + # check if the post request has the file part - if 'file' not in request.files: - flash('No file part') - return redirect(request.url) - file = request.files['file'] + #if 'file' not in request.files: + # flash('No file part') + # return redirect(request.url) + #file = request.files['file'] # if user does not select file, browser also # submit an empty part without filename - if file.filename == '': - flash('No selected file') - return redirect(request.url) - if file and allowed_file(file.filename): - filename = secure_filename(file.filename) - uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], filename) - file.save(uploadfilepath) + #if file.filename == '': + # flash('No selected file') + # return redirect(request.url) + #if file and allowed_file(file.filename): + # filename = secure_filename(file.filename) + # uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], filename) + # file.save(uploadfilepath) # return redirect(url_for('uploaded_file', # filename=filename)) - hocr_result = pdftotree.parse(uploadfilepath) - app.logger.info("test") - hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) - hocr.to_pdf( - out_filename='static/pdf/output-2.pdf', - image_filename='static/images/blank.png', - show_bounding_boxes=False, - interword_spaces=False, - ) + + hocr_result = pdftotree.parse(uploadfilepath) + app.logger.info("test") + hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) + hocr.to_pdf( + out_filename='static/pdf/output-2.pdf', + image_filename='static/images/blank.png', + show_bounding_boxes=False, + interword_spaces=False, + ) - hocrfile='static/hocr/gynaikoktonia.hocr' + #hocrfile='static/hocr/gynaikoktonia.hocr' #hocr = HocrTransform(hocr_filename=hocrfile, dpi=300) #hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) #hocr.to_pdf( @@ -64,7 +78,7 @@ def run_script(): # show_bounding_boxes=False, # interword_spaces=False, #) - # result = subprocess.check_output("python3 hocrtransformpdf.py -i images/blank.png hocr/gynaikoktonia.hocr pdf/gynaikoktonia.pdf", shell=True) +# result = subprocess.check_output("python3 hocrtransformpdf.py -i images/blank.png hocr/gynaikoktonia.hocr pdf/gynaikoktonia.pdf", shell=True) return render_template('results.html', **locals()) diff --git a/templates/.results.html.swp b/templates/.results.html.swp new file mode 100644 index 0000000000000000000000000000000000000000..7b655b769e5e0356e3c44ef2e19071e1f5df106b GIT binary patch literal 1024 zcmYc?$V<%2S1{HyVn6{RZVU{iMLCHmf;c$k`9&$YK#W5gF05acSfpQGUap@}lAEJn zke`{CnVny(2h*-wTBMhgs9%zrTac4jl3J`^lv-SxQ&Ox4QVus{lrb6tqai?U2!x_* F1OQfzAR7Px literal 0 HcmV?d00001 diff --git a/templates/results.html b/templates/results.html index ccbe22a..ffa4be7 100644 --- a/templates/results.html +++ b/templates/results.html @@ -3,12 +3,12 @@ {% block content %} - +
@@ -16,7 +16,7 @@
-
- + @@ -48,6 +48,8 @@
+
+