Browse Source

half way setting up the app.py for downloading file from url

master
nglk 2 years ago
parent
commit
f2a7a8d000
  1. BIN
      __pycache__/app.cpython-37.pyc
  2. 60
      app.py
  3. BIN
      templates/.results.html.swp
  4. 8
      templates/results.html

BIN
__pycache__/app.cpython-37.pyc

Binary file not shown.

60
app.py

@ -20,7 +20,7 @@ app.config['BASIC_AUTH_PASSWORD'] = 'tentacles'
basic_auth = BasicAuth(app) basic_auth = BasicAuth(app)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER app.config['UPLOAD_FOLDER'] = "static/pdf"
@app.route('/', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST'])
@ -28,34 +28,48 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def run_script(): 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 # 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': 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 # check if the post request has the file part
if 'file' not in request.files: #if 'file' not in request.files:
flash('No file part') # flash('No file part')
return redirect(request.url) # return redirect(request.url)
file = request.files['file'] #file = request.files['file']
# if user does not select file, browser also # if user does not select file, browser also
# submit an empty part without filename # submit an empty part without filename
if file.filename == '': #if file.filename == '':
flash('No selected file') # flash('No selected file')
return redirect(request.url) # return redirect(request.url)
if file and allowed_file(file.filename): #if file and allowed_file(file.filename):
filename = secure_filename(file.filename) # filename = secure_filename(file.filename)
uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], filename) # uploadfilepath=os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(uploadfilepath) # file.save(uploadfilepath)
# return redirect(url_for('uploaded_file', # return redirect(url_for('uploaded_file',
# filename=filename)) # filename=filename))
hocr_result = pdftotree.parse(uploadfilepath)
app.logger.info("test") hocr_result = pdftotree.parse(uploadfilepath)
hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) app.logger.info("test")
hocr.to_pdf( hocr = HocrTransform(hocr_filename=hocr_result, dpi=300)
out_filename='static/pdf/output-2.pdf', hocr.to_pdf(
image_filename='static/images/blank.png', out_filename='static/pdf/output-2.pdf',
show_bounding_boxes=False, image_filename='static/images/blank.png',
interword_spaces=False, 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=hocrfile, dpi=300)
#hocr = HocrTransform(hocr_filename=hocr_result, dpi=300) #hocr = HocrTransform(hocr_filename=hocr_result, dpi=300)
#hocr.to_pdf( #hocr.to_pdf(
@ -64,7 +78,7 @@ def run_script():
# show_bounding_boxes=False, # show_bounding_boxes=False,
# interword_spaces=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()) return render_template('results.html', **locals())

BIN
templates/.results.html.swp

Binary file not shown.

8
templates/results.html

@ -3,12 +3,12 @@
{% block content %} {% block content %}
<!-- <iframe src="https://pad.vvvvvvaria.org/wordmord.test" height="800" width="800"></iframe> --> <!-- <iframe src="https://pad.vvvvvvaria.org/wordmord.test" height="800" width="800"></iframe> -->
<form method="post">
<table> <table>
<tr> <tr>
<td colspan="3"> <td colspan="3">
<!-- <input type="text" id="my_field" value="" wrap="soft"> --> <!-- <input type="text" id="my_field" value="" wrap="soft"> -->
<textarea name="text" id="my_field" wrap="soft" placeholder="Επικόλληση του συνδέσμου του PDF του Ποινικού Κώδικα που βρήκατε στο ηλεκτρονικό ταχυδρομείο σας ή στο ΔΙΑΒΑΣΕΜΕ.txt, εδώ. <textarea name="file" id="my_field" wrap="soft" placeholder="Επικόλληση του συνδέσμου του PDF του Ποινικού Κώδικα που βρήκατε στο ηλεκτρονικό ταχυδρομείο σας ή στο ΔΙΑΒΑΣΕΜΕ.txt, εδώ.
"></textarea> "></textarea>
</td> </td>
</tr> </tr>
@ -16,7 +16,7 @@
<td colspan="3"> <td colspan="3">
<button id="button3" onclick="readme()">ΔΙΑΒΑΣΕΜΕ.txt</button> <button id="button3" onclick="readme()">ΔΙΑΒΑΣΕΜΕ.txt</button>
<button id="button5" onclick="decode()">ΠΡΟΒΟΛΗ ΠΟΙΝΙΚΟΥ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/closed.gif')}}"></button> <button id="button5" type="submit" onclick="decode()">ΠΡΟΒΟΛΗ ΠΟΙΝΙΚΟΥ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/closed.gif')}}"></button>
<button id="button2" onclick="copy()"> ΑΝΤΙΓΡΑΦΗ ΚΩΔΙΚΑ</button> <button id="button2" onclick="copy()"> ΑΝΤΙΓΡΑΦΗ ΚΩΔΙΚΑ</button>
<button id="button1" onclick="transform()">ΜΕΤΑΛΛΑΓΜΕΝΟΣ ΚΩΔΙΚΑΣ</button> <button id="button1" onclick="transform()">ΜΕΤΑΛΛΑΓΜΕΝΟΣ ΚΩΔΙΚΑΣ</button>
<button id="button4" onclick="window.open('{{url_for('static', filename='pdf/ΣΧΕΔΙΟ_ΜΕΤΑΛΛΑΓΜΕΝΟΥ_ΠΟΙΝΙΚΟΥ_ΚΩΔΙΚΑ_01.pdf')}}');">ΚΑΤΕΒΑΣΕ ΜΕΤΑΛΛΑΓΜΕΝΟ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/open.gif')}}"> </button> <button id="button4" onclick="window.open('{{url_for('static', filename='pdf/ΣΧΕΔΙΟ_ΜΕΤΑΛΛΑΓΜΕΝΟΥ_ΠΟΙΝΙΚΟΥ_ΚΩΔΙΚΑ_01.pdf')}}');">ΚΑΤΕΒΑΣΕ ΜΕΤΑΛΛΑΓΜΕΝΟ ΚΩΔΙΚΑ <img src="{{url_for('static', filename='images/open.gif')}}"> </button>
@ -48,6 +48,8 @@
</table> </table>
</form>
<script> <script>

Loading…
Cancel
Save