zeroth
6 years ago
4 changed files with 47 additions and 127 deletions
Binary file not shown.
@ -1,123 +0,0 @@ |
|||
from flask import Flask, url_for, render_template, Markup, redirect, request, flash, session, make_response |
|||
from config import Config |
|||
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") |
|||
app.jinja_env.add_extension('jinja2.ext.loopcontrols') |
|||
app.config.from_object(Config) |
|||
|
|||
#############cookie stuff |
|||
# app.secret_key = os.urandom(24) |
|||
|
|||
# setting variables for holding paths, folder names and the one file for description |
|||
path = "static/files/" |
|||
jsonfiles = [] #json files |
|||
fullpathjsonfiles = [] #fullpath for some situations |
|||
listingfiles= [] #fullpaths |
|||
listingdirectories = [] #paths |
|||
thefile = None #selected file for description |
|||
now = strftime("%Y-%m-%d_%H:%M:%S", gmtime()) #description time |
|||
positioninarray = 8 #counter |
|||
listofdicts=[] #to be able to import and use json content |
|||
datafromjson = [] |
|||
|
|||
#test getting json file from id |
|||
id = "17" |
|||
jsonfilefordescription = "files/"+id+"/"+id+".json" |
|||
|
|||
#arrays with the user path of words and numbers |
|||
pathofwords = [] |
|||
pathofnumbers = [] |
|||
|
|||
#listing paths and files, not in order but well... |
|||
for path, subdirs, files in os.walk(path): |
|||
for name in files: |
|||
#excluding json files from listing :-) |
|||
if not name.endswith(".json") and not name.endswith(".DS_Store"): |
|||
fullpath = os.path.join(path, name) |
|||
listingdirectories.append(path) |
|||
listingfiles.append(fullpath[7:]) #fullpaths minus static/ |
|||
|
|||
if name.endswith(".json"): |
|||
fullpath = os.path.join(path, name) |
|||
jsonfiles.append(fullpath[7:]) |
|||
# print(name) |
|||
# for line in open(fullpath, "r"): |
|||
# listofdicts.append(json.loads(line)) |
|||
|
|||
#================================================= |
|||
#listing the json paths |
|||
for path, subdirs, files in os.walk(path): |
|||
for name in files: |
|||
if name.endswith(".json"): |
|||
fullpath = os.path.join(path, name) |
|||
jsonfiles.append(fullpath[7:]) |
|||
fullpathjsonfiles.append(fullpath) |
|||
|
|||
print(jsonfiles) |
|||
print("-------------------------") |
|||
|
|||
|
|||
dict = {} #dict for the form entries |
|||
|
|||
|
|||
with open("static/"+jsonfiles[4], 'r') as f: |
|||
data_dict = json.load(f) |
|||
datafromjson = data_dict["files"] |
|||
print(datafromjson) |
|||
|
|||
@app.route("/") |
|||
def home(): |
|||
words = ["way", "blablabla", "uqhdiuqsiud"] |
|||
res = make_response(render_template('home.html')) |
|||
res.set_cookie("qhdqhd",str(words) , max_age=60*60*24*365*2) |
|||
return res |
|||
|
|||
@app.route('/about/') |
|||
def about(): |
|||
return render_template('about.html') |
|||
|
|||
@app.route('/all/') |
|||
def all(): |
|||
thefile = listingfiles[positioninarray] |
|||
print(listingfiles) |
|||
# print(dict) |
|||
counter2=0 |
|||
return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts, counter2=counter2) |
|||
|
|||
@app.route('/description') |
|||
def description(): |
|||
#open json file, list filepaths in array and loop with thefile |
|||
textfile="" |
|||
with open("static/"+jsonfilefordescription, 'r') as f: |
|||
data_dict = json.load(f) |
|||
datafromjson = data_dict["files"] |
|||
itemid = data_dict["id"] |
|||
for file in datafromjson: |
|||
if file.lower().endswith(('.html')): |
|||
with open("static/"+file,"r", encoding='utf-8') as f: |
|||
textfile = f.read() |
|||
word = "way" |
|||
wordlinked = "<a href='/diverge?search="+word+"'>"+word+"</a>" |
|||
textfile = re.sub(word, wordlinked, textfile) |
|||
|
|||
textfile = Markup(textfile) |
|||
|
|||
return render_template('description.html', datafromjson=datafromjson, itemid=itemid, textfile=textfile) |
|||
|
|||
@app.route('/diverge', methods=['GET']) |
|||
def diverge(): |
|||
searchterm=request.args.get('search') |
|||
return render_template('diverge.html', searchterm=searchterm) |
|||
|
|||
@app.route('/listofwords') |
|||
def listofwords(): |
|||
return render_template('listofwords.html') |
|||
|
|||
if __name__ == '__main__': |
|||
app.run(debug=True) |
@ -1,11 +1,19 @@ |
|||
{% extends "layout.html" %} |
|||
{% block content %} |
|||
|
|||
<p>test</p> |
|||
<p>{{ searchterm }}</p> |
|||
<p>{{ searchterm }} : </p> |
|||
{% for word in wordlist_dict %} |
|||
{% if word==searchterm %} |
|||
{{word[0]['way']}} |
|||
{% if searchterm == word %} |
|||
{% set length_d = wordlist_dict[word]|length %} |
|||
|
|||
{% for item in wordlist_dict[word] %} |
|||
{% set address = "/description?id=" + item['id'] %} |
|||
<a href={{address}}> |
|||
{{ item['sentence'] }} |
|||
</a><br> |
|||
{% endfor %} |
|||
|
|||
{% endif %} |
|||
{% endfor %} |
|||
|
|||
{% endblock %} |
|||
|
@ -0,0 +1,35 @@ |
|||
{ |
|||
"way" : [ |
|||
{ |
|||
"id" : "17", |
|||
"sentence" : "He described his own art as a way of 'ensuring that the details of everyday life, the random constellations of objects that surround us, stop going unnoticed.'" |
|||
}, |
|||
|
|||
{ |
|||
"id" : "17", |
|||
"sentence" : "Another sentence like way way this." |
|||
}, |
|||
|
|||
{ |
|||
"id" : "00", |
|||
"sentence" : "Our ambition, and that of our collaborating partners, is to emancipate graphic notation from the confines of the modernist tradition, in such a way that it may remain an innovative and provocative medium for decades to come." |
|||
} |
|||
], |
|||
|
|||
"artwork" : [ |
|||
{ |
|||
"id" : "17", |
|||
"sentence" : "One of the originators of 'participatory' art, in which the artwork can only be experienced by the active involvement of the viewer, he is most famous for his Event Scores such as Drip Music 1962, and is widely seen as an important precursor to conceptual art." |
|||
}, |
|||
{ |
|||
"id" : "00", |
|||
"sentence" : "It unfolds through a nomadic program which includes the creation of newly commissioned artworks and public events that addres scontemporary questions and issues in this particular field." |
|||
}, |
|||
{ |
|||
"id" : "00", |
|||
"sentence" : "The discursive program for 2016–2017 will include lectures, presentations of newly commissioned artworks, concert evenings, and workshops." |
|||
} |
|||
|
|||
] |
|||
|
|||
} |
Loading…
Reference in new issue