cookie stuff
This commit is contained in:
parent
83fb6a3db9
commit
6edd57f58a
Binary file not shown.
142
contextualise.py
Normal file
142
contextualise.py
Normal file
@ -0,0 +1,142 @@
|
||||
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 = []
|
||||
|
||||
#reading wordlist.json
|
||||
with open('wordlist_v3.json', 'r') as f:
|
||||
wordlist_dict = json.load(f)
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
# with open("static/"+jsonfilefordescription, 'r') as f:
|
||||
# data_dict = json.load(f)
|
||||
# datafromjson = data_dict["files"]
|
||||
# print(datafromjson)
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
words = ["way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud","way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "way", "blablabla", "uqhdiuqsiud", "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():
|
||||
idno=request.args.get('id')
|
||||
jsonfilefordescription = "files/"+idno+"/"+idno+".json"
|
||||
with open("static/"+jsonfilefordescription, 'r') as f:
|
||||
data_dict = json.load(f)
|
||||
datafromjson = data_dict["files"]
|
||||
#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, idno=idno)
|
||||
|
||||
@app.route('/diverge', methods=['GET'])
|
||||
def diverge():
|
||||
searchterm=request.args.get('search')
|
||||
return render_template('diverge.html', searchterm=searchterm)
|
||||
|
||||
@app.route('/listofwords')
|
||||
def listofwords():
|
||||
cookie = request.cookies.get("qhdqhd")
|
||||
cookie.set_cookie("qhdqhd", "pulamemevaleur")
|
||||
|
||||
return render_template('listofwords.html', cookie=cookie)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
@ -1,3 +1,11 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% if cookie is defined %}
|
||||
{{ cookie }}
|
||||
{% endif %}
|
||||
|
||||
<p>lol</p>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user