regex link fine

This commit is contained in:
zeroth 2019-04-16 15:58:52 +01:00
parent ad9a518495
commit 0795636bd2
3 changed files with 17 additions and 32 deletions

View File

@ -5,6 +5,7 @@ import json
import os import os
from time import gmtime, strftime from time import gmtime, strftime
from pprint import pprint from pprint import pprint
import re
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
@ -81,7 +82,7 @@ def all():
# print(dict) # print(dict)
counter2=0 counter2=0
return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2) return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2)
@app.route('/description') @app.route('/description')
def description(): def description():
@ -93,40 +94,24 @@ def description():
for file in datafromjson: for file in datafromjson:
# # assigning html tag on the basis of extension, to be finished when all the files have been sent
# if file.lower().endswith(('.png', '.jpg', '.jpeg')):
# file = Markup('<img src="'+file[7:]+'" /> <br />')
# #if sound
# elif file.lower().endswith(('.mp3')):
# file = Markup('''<audio controls>
# <source src="'''+file+'''" type="audio/mpeg">
# Your browser does not support the audio tag.
# </audio>''')
#if txtfile
# if file.lower().endswith(('.txt')):
# # print(thefile)
# with open("static/"+file,"r") as f:
# textfile = f.readlines()
if file.lower().endswith(('.html')): if file.lower().endswith(('.html')):
# print(thefile)
with open("static/"+file,"r", encoding='utf-8') as f: with open("static/"+file,"r", encoding='utf-8') as f:
textfile = f.read() textfile = f.read()
word = "way"
wordlinked = "<a href='/diverge?search="+word+"'>"+word+"</a>"
textfile = re.sub(word, wordlinked, textfile)
# go into the textfile content, find the words,
# replace word with <a href="/diverge?search=word">word</a>
textfile = Markup(textfile) textfile = Markup(textfile)
# #ifvid to be added
# elif file.lower().endswith(('.mp4')):
# file = Markup(''' <video width="320" height="240" controls>
# <source src="'''+thefile+'''" type="video/mp4">
# Your browser does not support the video tag.
# </video> ''')
return render_template('description.html', datafromjson=datafromjson, itemid=itemid, textfile=textfile) return render_template('description.html', datafromjson=datafromjson, itemid=itemid, textfile=textfile)
@app.route('/diverge')
def diverge():
return render_template('diverge.html')
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True) app.run(debug=True)

View File

@ -15,13 +15,13 @@
<div> <div>
<img class="img-responsive" src=" ../{{ item }}"> <img class="img-responsive" src=" ../{{ item }}">
</div> </div>
{% elif item.lower().endswith(('.mp4')) %} {% elif item.lower().endswith(('.mp4')) %}
<div><video width="320" height="240" controls><source src="../{{ item }}" type="video/mp4"> <div><video width="320" height="240" controls><source src="../{{ item }}" type="video/mp4">
Your browser does not support the video tag. Your browser does not support the video tag.
</video> </video>
</div> </div>
{% elif item.lower().endswith(('.mp3')) %} {% elif item.lower().endswith(('.mp3')) %}
<div><audio controls><source src="../{{ item }}" type="audio/mpeg"> <div><audio controls><source src="../{{ item }}" type="audio/mpeg">
Your browser does not support the audio tag. Your browser does not support the audio tag.
@ -32,7 +32,7 @@
{% endfor %} {% endfor %}
{% if textfile is defined %} {% if textfile is defined %}
<pre>{{ textfile }}</pr>e <pre>{{ textfile }}</pre>
{% endif %} {% endif %}