Browse Source

regex link fine

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

BIN
__pycache__/contextualise.cpython-35.pyc

Binary file not shown.

35
contextualise.py

@ -5,6 +5,7 @@ import json
import os
from time import gmtime, strftime
from pprint import pprint
import re
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
@ -93,40 +94,24 @@ def description():
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')):
# print(thefile)
with open("static/"+file,"r", encoding='utf-8') as f:
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)
@app.route('/diverge')
def diverge():
return render_template('diverge.html')
if __name__ == '__main__':
app.run(debug=True)

2
templates/description.html

@ -32,7 +32,7 @@
{% endfor %}
{% if textfile is defined %}
<pre>{{ textfile }}</pr>e
<pre>{{ textfile }}</pre>
{% endif %}

Loading…
Cancel
Save