Commit 7942b98e authored by colm's avatar colm

main change is moving to regex and replace methods in Flask instead of on the...

main change is moving to regex and replace methods in Flask instead of on the csv files themselves, so when building the general dict, the invetoryNb formatting issues are fixed then. Also regex for adding a span to the word_patterns to hightlight. Added routes for the various static pages, not all done yet. Lastly, removed the debug=true for deployment tests
parent 2a34c462
......@@ -2,42 +2,57 @@ from flask import Flask, render_template, redirect
import csv
import os
import glob
import re
app = Flask(__name__)
thisdir = os.getcwd()
print(thisdir)
pattern0 = r'(probabl\w*)'
pattern1 = r'(possibl\w*)'
pattern2 = r'(peut)'
pattern3 = r'\s(être)'
pattern4 = r'(peut\-être)'
replace0 = r'<span class="uncertain_match">\1</span>'
replace1 = r'<span class="uncertain_match"> \1</span>'
uncertainlist = glob.glob('static/word_patterns/*.csv')
full_dict = {}
full_counter = 0
for file in uncertainlist:
filename = file.split('/')[2]
filename = filename.split('.')[0]
print(filename)
file = open(file)
file = csv.reader(file)
currentlist = []
for row in file:
row[1] = row[1].replace(" ", "-")
row[1] = row[1].replace(".", "-")
row[11] = re.sub(pattern4, replace0, row[11])
row[11] = re.sub(pattern0, replace0, row[11])
row[11] = re.sub(pattern1, replace0, row[11])
row[11] = re.sub(pattern2, replace0, row[11])
row[11] = re.sub(pattern3, replace1, row[11])
currentlist.append(row)
full_counter += 1
full_dict[filename] = currentlist
print(full_counter)
amounts = []
for word, results in full_dict.items():
word_amount = word, len(results)
amounts.append(word_amount)
uncertainlist = glob.glob('static/word_patterns/*.csv')
uncertainlist = [i.split('/')[2] for i in uncertainlist]
uncertainlist = [i.split('.')[0] for i in uncertainlist]
@app.route("/")
def home():
print(full_dict)
uncertainlist = glob.glob('static/word_patterns/*.csv')
uncertainlist = [i.split('/')[2] for i in uncertainlist]
uncertainlist = [i.split('.')[0] for i in uncertainlist]
data_file = open('scrape_probabl.csv')
csv_file = csv.reader(data_file)
file = csv.reader(data_file)
for row in file:
print(row[11])
return render_template("index.html", full_dict=full_dict, uncertainlist=uncertainlist, csv_file=csv_file, file=file, full_counter=full_counter)
return render_template("index.html", full_dict=full_dict, uncertainlist=uncertainlist, csv_file=csv_file, file=file, full_counter=full_counter, amounts=amounts)
@app.route('/collection/<uncertain>')
def word_pattern(uncertain):
......@@ -55,9 +70,17 @@ def word_pattern(uncertain):
return render_template("uncertain.html", uncertain=uncertain, datafile=datafile)
@app.route("/about")
def about():
return render_template("about.html", full_counter=full_counter)
@app.route("/news")
def news():
return render_template("news.html", full_dict=full_dict, full_counter=full_counter, amounts=amounts)
@app.errorhandler(404)
def not_found(error):
return render_template('error.html'), 404
if __name__ == '__main__':
app.run(host='0.0.0.0', port='5001', debug=True)
app.run(host='0.0.0.0', port='5001')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment