description improved

This commit is contained in:
zeroth 2019-04-15 15:22:07 +01:00
parent fc924d0c35
commit d27621615a
11 changed files with 359 additions and 86 deletions

View File

@ -1,9 +1,5 @@
from flask import Flask, url_for, render_template, Markup, redirect, request, flash
from flask import session as login_session
from flask_wtf import FlaskForm
from wtforms.validators import DataRequired
from wtforms import Form, TextField, TextAreaField, BooleanField, validators, StringField, SubmitField
from forms import ReusableForm
from config import Config
import json
import os
@ -16,103 +12,114 @@ app.jinja_env.add_extension('jinja2.ext.loopcontrols')
app.config.from_object(Config)
#### THE CHECKBOX RESULT DOESNT GET RECORDED TO THE JSON FILE
#### FULL LOOP WITH FILE AND RELOADING THE FORM WITH NEXT FILE IN THE ARRAY HAS TO BE MADE
#### OPTIONS TO SWITCH BETWEEN FILES NEED TO BE AVAILABLE
#### MAYBE CONFIRMATION BEFORE JSON IS RECORDED TO FORCE PEOPLE TO DOUBLE THINK
# 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
jsonfiles = [] #json files
fullpathjsonfiles = [] #fullpath for some situations
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 = []
#listing paths and files, not in order but well...
for path, subdirs, files in os.walk(path):
for name in files:
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/
# print (path)
# print (name)
# print (os.path.join(path, name))
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))
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("-------------------------")
# print(listofdicts[0]["name"]) #test
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():
return render_template('home.html')
return render_template('home.html')
@app.route('/about/')
def about():
return render_template('about.html')
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)
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():
#pick a file but that will be done an other way later
thefile = listingfiles[positioninarray] #select one file from fullpath minus static/
#open json file, list filepaths in array and loop with thefile
with open("static/"+jsonfiles[4], 'r') as f:
data_dict = json.load(f)
datafromjson = data_dict["files"]
itemid = data_dict["id"]
# assigning html tag on the basis of extension, to be finished when all the files have been sent
if thefile.lower().endswith(('.png', '.jpg', '.jpeg')):
thefile = Markup('<img src="'+thefile+'" /> <br />')
for file in datafromjson:
#if sound
elif thefile.lower().endswith(('.mp3')):
thefile = Markup('''<audio controls>
<source src="'''+thefile+'''" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>''')
#if txtfile
elif thefile.lower().endswith(('.txt')):
# print(thefile)
# # 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 />')
with open("static/"+thefile,"r") as f:
path = f.read()
thefile = path
# #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.read()
# yotxt = open(thefile, 'r+')
# thefile = text.read()
# text.close()
# #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> ''')
# thefile = Markup('''<iframe src="'''+thefile+'''">
# ''')
#ifvid to be added
elif thefile.lower().endswith(('.mp4')):
thefile = Markup(''' <video width="320" height="240" controls>
<source src="'''+thefile+'''" type="video/mp4">
Your browser does not support the video tag.
</video> ''')
return render_template('description.html', file=thefile)
return render_template('description.html', datafromjson=datafromjson, itemid=itemid, textfile=textfile)
if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True)

View File

@ -1,6 +1,19 @@
body{
background: lavender;
background: #ffffff;
color:blue;
}
ul{
list-style: none;
}
li a{
text-decoration: none;
color: #0000FF
}
li a:hover{
color: orange;
}
img{

View File

@ -1 +1,13 @@
{"id": "00.", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."}
{
"id": "00.",
"name": "Yes",
"email": "sure@whynot.com",
"friend": "Y",
"content": "A sound file.",
"files":[
"static/files/00. Pushing Scores/Participants.txt",
"static/files/00. Pushing Scores/PushingScores.txt",
"static/files/00. Pushing Scores/events.txt"
]
}

View File

@ -1 +1,11 @@
{"id": "01.", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."}
{
"id": "01.",
"name": "Yes",
"email": "sure@whynot.com",
"friend": "Y",
"content": "A sound file.",
"files": [
"static/files/01. Event Tetra Gamma Circulaire 1/01.metadata.txt",
"static/files/01. Event Tetra Gamma Circulaire 1/Photo/TGC1club-web-06 februari 2015-02.jpg"
]
}

View File

@ -1 +1,16 @@
{"id": "02.", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."}
{
"id": "02.",
"name": "Yes",
"email": "sure@whynot.com",
"friend": "Y",
"content": "A sound file.",
"files": [
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/02.metadata.txt",
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/Photo/Scan Manual BACK 300dpi.jpg",
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/Photo/Scan Manual FRONT 300dpi.jpg",
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/Photo/TGC3achterkant.jpg",
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/Photo/TGC3.jpg",
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/Photo/TGC3 top.jpg",
"static/files/02. release DOB084 Tetra Gamma Circulaire 3/Photo/TGC3voorkant.jpg"
]
}

View File

@ -1 +1,11 @@
{"id": "03.", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."}
{
"id": "03.",
"name": "Yes",
"email": "sure@whynot.com",
"friend": "Y",
"content": "A sound file.",
"files": [
"static/files/03.150702 Kris Principium2 Stadslimiet Antwerpen/03.metadata.txt",
"static/files/03.150702 Kris Principium2 Stadslimiet Antwerpen/Photo/Kris princ2-s-2000px-72dpi-79 02 juli 2015.jpg"
]
}

View File

@ -1 +1,16 @@
{"id": "05.", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."}
{
"id": "05.",
"name": "Yes",
"email": "sure@whynot.com",
"friend": "Y",
"content": "A sound file.",
"files": [
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/05.metadata.txt",
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/Sound/DOB079_VaastColson_CarlsonInvents.mp3",
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/Photo/DOB079-Vaast-Colson-spread-1600px-web-160913-1.jpg",
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/Photo/DOB079-Vaast-Colson-1600px-web-160913-11.jpg",
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/Photo/ArtBookFairBrussel-Vaast Colson-6d-20160909-57-20.jpg",
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/Photo/DOB079-Vaast-Colson-1600px-web-160913-10.jpg",
"static/files/05. 160909 Wiels ArtbookFair Vaast Colson/Photo/VaastColson.jpg"
]
}

View File

@ -1 +1,12 @@
{"id": "17.", "Who": "George Brecht", "What": "Works", "content": "A sound file."}
{
"id": "17.",
"Who": "George Brecht",
"What": "Works",
"content": "A sound file.",
"files": [
"files/17. George Brecht_event scores/17.blurb.txt",
"files/17. George Brecht_event scores/Photo/brecht-event1.jpg",
"files/17. George Brecht_event scores/Photo/svc-1966-brecht's sundown event-i.jpg",
"files/17. George Brecht_event scores/Video/Drip Music - George Brecht (Fluxus)-UT5lgaE-qZY.mkv"
]
}

View File

@ -1,21 +1,40 @@
{% extends "layout.html" %}
{% block content %}
<div class="description">
<h2 style = "text-align: center;">Write something very interesting here.</h2>
<h2 style = "text-align: center;">{{ itemid }}</h2>
<!--passing files-->
<p>{{ file }}</p>
<p>{{ datafromjson }}</p>
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
{% for item in datafromjson %}
{% if item.lower().endswith(('.png', '.jpg', '.jpeg')) %}
<div>
<img class="img-responsive" src=" ../{{ item }}">
</div>
{% elif item.lower().endswith(('.mp4')) %}
<div><video width="320" height="240" controls><source src="../{{ item }}" type="video/mp4">
Your browser does not support the video tag.
</video>
</div>
{% elif item.lower().endswith(('.mp3')) %}
<div><audio controls><source src="../{{ item }}" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
</div>
{% endif %}
{% endfor %}
{% if textfile is defined %}
<p>{{ textfile }}</p>
{% endif %}
<!-- <img src="{{ url_for('static', filename='/files/001/DwySYC4X4AESeRh.jpg') }}">
-->
<!--passing an array-->
<!-- {% for v in listingdirectories %}
<div>{{ v }}</div>
{% endfor %}
{% for f in listingfiles %}
<div>{{ f }}</div>
{% endfor %}
-->
</div>
{% endblock %}

161
wasteoftime.py Normal file
View File

@ -0,0 +1,161 @@
from flask import Flask, url_for, render_template, Markup, redirect, request, flash
from flask import session as login_session
from config import Config
import json
import os
from time import gmtime, strftime
from pprint import pprint
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)
# setting variables for holding paths, folder names and the one file for description
path = "static/files/"
jsonfiles = [] #json files
fullpathjsonfiles = [] #fullpath for some situations
thefile = None #selected file for description
now = strftime("%Y-%m-%d_%H:%M:%S", gmtime()) #description time
listofdicts=[] #to be able to import and use json content
#================================================================
#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("-------------------------")
print(fullpathjsonfiles)
#=================================================================
#obtaining files and data
# model for display :
# file+filename+data from json
# looping through json file, in files there is an array
# for each file in this array, display the file and the data
# send it all to the all page
allfiles = []
container = None
varid = None
name = None
email = None
friend = None
content = None
for jsonname in jsonfiles:
with open("static/"+jsonname, 'r') as ajson:
data = json.load(ajson)
# allfiles.append(data["files"])
for f in data["files"]:
# assigning html tag on the basis of extension, to be finished when all the files have been sent
if f.lower().endswith(('.png', '.jpg', '.jpeg')):
f = Markup('<img src="'+f+'" /> <br />')
#if sound
elif f.lower().endswith(('.mp3')):
f = Markup('''<audio controls>
<source src="'''+f+'''" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>''')
#if txtfile
elif f.lower().endswith(('.txt')):
# print(thefile)
with open(f,"r") as f:
path = f.read()
f = path
#ifvid to be added
elif f.lower().endswith(('.mp4')):
f = Markup(''' <video width="320" height="240" controls>
<source src="'''+f+'''" type="video/mp4">
Your browser does not support the video tag.
</video> ''')
for i in data["id"]:
varid.append(i)
for j in data["name"]:
name.append(j)
print("-------------------------")
print(allfiles)
#Going through all folders, getting the
# thefile = listingfiles[positioninarray]
@app.route("/")
def home():
return render_template('home.html')
@app.route('/about/')
def about():
return render_template('about.html')
@app.route('/all/')
def all():
for jsonname in jsonfiles:
with open("static/"+jsonname, 'r') as ajson:
data = json.load(ajson)
allfiles.append(data["files"])
print(allfiles)
#Going through all folders, getting the
# thefile = listingfiles[positioninarray]
print(jsonfiles)
# 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
with open(jsonfiles[1], 'r') as f:
data_dict = json.load(f)
datafromjson = data_dict["files"]
for file in datafromjson:
datafromjson = file
# 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+'" /> <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
elif file.lower().endswith(('.txt')):
# print(thefile)
with open(file,"r") as f:
path = f.read()
file = path
#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> ''')
return render_template('description.html', file=file, datafromjson=datafromjson)
# if __name__ == '__main__':
# app.run(debug=True)