2020-09-15 09:44:29 +02:00
|
|
|
from flask import Flask, render_template, Markup, jsonify
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
from json import dumps
|
|
|
|
|
|
|
|
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
|
|
|
|
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
|
|
|
|
|
|
|
|
|
|
|
|
# SETTING THE VARIABLES
|
|
|
|
path = "/static/files/"
|
|
|
|
|
|
|
|
#move this list to Jinja so it can be placed in layout
|
|
|
|
#give back clicked value
|
|
|
|
# librarians = ["Alana", "Gentian", "Laurie", "Matias", "Scott", "Stacy", "Max", "Clara_B", "Michelle", "Clara_J_B", "Karen", "Lumsden_Primary_School", "Aaron", "Leo", "Maria", "Laura", "Honey", "Tender_Center", "wdka", "Naomi", "Cristina", "Julie", "ssw", "cyberspace", "Hannah", "Katarina", "Anastasia", "Kimmy", "Marie","Katherine", "Allison", "Mariana", "Viki", "Alice", "Eric", "hks", "cbk", "Sophie", "Antonio", "Jeremiah", "Angela", "Renee", "Marta", "Katherine", "Anna", "Auryn", "Ashley", "Anne", "Denise", "Eva", "Jonnah", "Kitty", "Masha", "Mia", "Cian", "Senke", "Maud", "Jinnie", "Rubin", "Julia", "Alana", "Gentian", "Laurie", "Matias","Scott", "Stacy"]
|
|
|
|
|
|
|
|
librarians = []
|
|
|
|
files_without_folders = []
|
|
|
|
|
|
|
|
with open('static/js/mergedjson.json', 'r', encoding='utf8') as filesandnames:
|
|
|
|
filetoname_dict = json.load(filesandnames)
|
|
|
|
|
|
|
|
#get full list librarians from json (printed later through global variable)
|
|
|
|
for file in filetoname_dict:
|
|
|
|
for name in file["librarian"]:
|
|
|
|
librarians.append(str(name))
|
|
|
|
librarians = list(dict.fromkeys(librarians))
|
|
|
|
|
|
|
|
#this value we should get from template
|
|
|
|
librarianselected = "Ruben"
|
|
|
|
|
|
|
|
#go from librarian name to file
|
|
|
|
for file in filetoname_dict:
|
|
|
|
# if librarianselected in file["librarian"]:
|
|
|
|
thedebris = file["debrisname"]
|
|
|
|
#apply regex to the debris
|
|
|
|
thedebris = os.path.basename(thedebris)
|
|
|
|
files_without_folders.append(str(thedebris))
|
2020-10-09 20:10:50 +02:00
|
|
|
# print(str(librarianselected)+" contributed with the following debris : "+str(thedebris))
|
2020-09-15 09:44:29 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#this value we should get from template
|
|
|
|
fileselected = filetoname_dict[1]["debrisname"]
|
|
|
|
|
|
|
|
#go from file name to librarian name
|
|
|
|
for file in filetoname_dict:
|
|
|
|
if fileselected in file["debrisname"]:
|
|
|
|
thelibrarian = file["librarian"]
|
|
|
|
print("librarians for "+ str(fileselected)+" are: " + str(thelibrarian))
|
|
|
|
print("---------------------------------------------------")
|
|
|
|
|
|
|
|
print(librarians)
|
|
|
|
|
2020-10-09 20:10:50 +02:00
|
|
|
@app.route("/")
|
2020-09-15 09:44:29 +02:00
|
|
|
def home():
|
2020-10-09 20:10:50 +02:00
|
|
|
return render_template('layout.html', filetoname_dict=filetoname_dict, librarians=librarians, files_without_folders = files_without_folders)
|
2020-09-15 09:44:29 +02:00
|
|
|
|
|
|
|
@app.route('/about/')
|
|
|
|
def about():
|
|
|
|
return render_template('about.html')
|
|
|
|
|
|
|
|
@app.route('/exchange')
|
|
|
|
def exchange():
|
|
|
|
return render_template('exchange.html')
|