You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
161 lines
4.5 KiB
161 lines
4.5 KiB
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)
|