Browse Source

regex link fine

master
zeroth 6 years ago
parent
commit
0795636bd2
  1. BIN
      __pycache__/contextualise.cpython-35.pyc
  2. 41
      contextualise.py
  3. 6
      templates/description.html

BIN
__pycache__/contextualise.cpython-35.pyc

Binary file not shown.

41
contextualise.py

@ -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()
textfile = Markup(textfile) word = "way"
wordlinked = "<a href='/diverge?search="+word+"'>"+word+"</a>"
textfile = re.sub(word, wordlinked, 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> ''')
# go into the textfile content, find the words,
# replace word with <a href="/diverge?search=word">word</a>
textfile = Markup(textfile)
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)

6
templates/description.html

@ -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 %}

Loading…
Cancel
Save