Commit d4377aa7 authored by colm's avatar colm

mechanising the usage of .csv files from the word_patterns folder in the flask...

mechanising the usage of .csv files from the word_patterns folder in the flask static resources. Normally the structure will now allow for easy adding of future word patterns, and be able to pick images out of the corresponding folder. Using glob over os.listdir() meant a few changes in the main flask file too but we're mostly there
parent 3638a990
from flask import Flask, render_template, redirect
import csv
import os
import glob
app = Flask(__name__)
thisdir = os.getcwd()
print(thisdir)
uncertainlist = os.listdir("word_patterns/")
uncertainlist = glob.glob('static/word_patterns/*.csv')
full_dict = {}
for file in uncertainlist:
filename = file.split('.')[0]
filename = file.split('/')[2]
filename = filename.split('.')[0]
print(filename)
file = open('word_patterns/' + file)
file = open(file)
file = csv.reader(file)
currentlist = []
for row in file:
print(row)
currentlist.append(row)
full_dict[filename] = currentlist
@app.route("/")
def home():
print(full_dict)
uncertainlist = os.listdir("word_patterns/")
uncertainlist = glob.glob('static/word_patterns/*.csv')
uncertainlist = [i.split('/')[2] for i in uncertainlist]
uncertainlist = [i.split('.')[0] for i in uncertainlist]
path_to_imgs='probabl/'
data_file = open('scrape_probabl.csv')
csv_file = csv.reader(data_file)
file = csv.reader(data_file)
return render_template("index.html", full_dict=full_dict, uncertainlist=uncertainlist, csv_file=csv_file, path_to_imgs=path_to_imgs, file=file)
return render_template("index.html", full_dict=full_dict, uncertainlist=uncertainlist, csv_file=csv_file, file=file)
@app.route('/collection/<uncertain>')
def word_pattern(uncertain):
uncertainlist = os.listdir("word_patterns/")
uncertainlist = glob.glob('static/word_patterns/*.csv')
uncertainlist = [i.split('/')[2] for i in uncertainlist]
uncertainlist = [i.split('.')[0] for i in uncertainlist]
print(uncertainlist)
if uncertain in uncertainlist:
print('this is a file')
filename = 'word_patterns/' + uncertain + '.csv'
filename = 'static/word_patterns/' + uncertain + '.csv'
datafile = open(filename)
datafile = csv.reader(datafile)
print(filename)
......
......@@ -262,6 +262,10 @@ img.thumbnail {
height: auto;
}
img.large-thumbnail {
width: 400px;
}
/* ::Import styles */
/* ------------------------------------------------------------ */
h1 {
......
......@@ -58,6 +58,10 @@ img.thumbnail{
height: auto;
}
img.large-thumbnail{
width: 400px;
}
/* ::Import styles */
/* ------------------------------------------------------------ */
......
......@@ -30,14 +30,6 @@
<hr>
{% endblock nav %}
{% block language %}
<div class="language-switcher">
<a href="#en">en</a>
<a href="#fr">fr</a>
<a href="#nl">nl</a>
</div>
{% endblock language %}
{% block content %}
{% endblock content %}
......
......@@ -3,25 +3,20 @@
{% block content %}
<div class="row-parent">
<div class="row">
<div class="colspan12-12 as-grid">
{{full_dict}}
{% for row in full_dict %}
{{row}}
{% endfor %}
<hr>
</div>
<div class="colspan12-6 as-grid">
{% for row in file %}
<img class="thumbnail" src="/static/probabl/{{row[13]}}">
{% endfor %}
{% for word, results in full_dict.items() %}
{% for result in results[1:] %}
<img class="thumbnail" src="/static/word_patterns/{{word}}/{{result[13]}}">
{% endfor %}
<hr>
{% endfor %}
</div>
<div class="colspan12-6 as-grid">
{% for row in csv_file %}
{% if loop.index == 1 %}
Column names are: {{row}}<br><br><br>
{% else %}
{{loop.index}} : {{row}}<br><br>
{% endif %}
{% for word, results in full_dict.items() %}
{% for result in results[1:] %}
{{loop.index}} : {{result}} // <br>
{% endfor %}
<hr>
{% endfor %}
</div>
</div>
......
......@@ -3,17 +3,18 @@
{% block content %}
<div class="row-parent">
<h1>{{uncertain}}</h1>
<div class="row">
<h1>{{uncertain}}</h1>
<hr>
{% for row in datafile %}
<div class="row__colspaced">
<div class="colspan12-8 as-grid with-gutter">
<h2>{{loop.index}} {{row[2]}} : </h2>
<p>{{row}}</p><br>
</div>
<div class="colspan12-4 as-grid with-gutter">
<small>{{row[2]}}, {{row[3]}}: </small>
<p><img src="/static/probabl/{{row[13]}}"></p>
<p><img class="large-thumbnail" src="/static/word_patterns/{{uncertain}}/{{row[13]}}"></p>
</div>
<div class="colspan12-8 as-grid with-gutter">
<h2>{{loop.index}} {{row[2]}} : </h2>
<p>{{row}}</p><br>
</div>
</div>
{% endfor %}
......
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