From 6edd57f58adc6d4c8cb80f0d231f24a34bfd3168 Mon Sep 17 00:00:00 2001 From: zeroth Date: Wed, 17 Apr 2019 18:31:33 +0100 Subject: [PATCH] cookie stuff --- __pycache__/contextualise.cpython-35.pyc | Bin 3607 -> 4605 bytes contextualise.py | 142 +++++++++++++++++++++++ templates/listofwords.html | 8 ++ 3 files changed, 150 insertions(+) create mode 100644 contextualise.py diff --git a/__pycache__/contextualise.cpython-35.pyc b/__pycache__/contextualise.cpython-35.pyc index 6e181bbe6597b72c626c3a6ca466cb460c9e91fd..85c6777fc05ce3793fea4a9df3c1d8e7bf6a93d0 100644 GIT binary patch literal 4605 zcmeHK&2tmU6@NV%ec2NJz_u`E!LS%3z!tFV^07du0K0@_y#%rGW{RvbcDJmNXEbup z2#m_EO3L{-a@#|WslB9fO;s+r=8wo!<*=2LE9YGHviZFpi8!!HRc<+~EWPRJe*OA= z{a!y;%H@&k?jN6yA0zr39r#RQd5S3JT;DC@7LsB*FVF@<%8bC1*5!&yZgtr(|SfTqdV%#y0tfC>SGWjDm4; z##8Pr`4bdOkTdaW_ar%!qy(wMBy%M5Bnu>qBu7Y&(w@jTQ>3P-Jx%Qyk|oTL;P(+~ zS4c4jB;nK}v_a&|8hX^wIYW<;gn@678Yg*()EMm%?ZNQlB%$01!!vK_Ns>_X6v+uv zr>G()sbZdosp7nCI8Gb7K$ATW}~kHSNw-!V~`9|=sL2`b$bal97 zL`Wpe+ry=6!==+^*8<5i!=>xPrA3lwNmgk?fJex4B+n0dZVY)YnC(j>mxoL58+_Dg z(<1$s3BMSciVpAIPdTJzqt&{=~wMmllGh1=(15aAV=48w>UQ z0({|Em#+46DbH7;*3T}tqp;H-e;#V-dr{nY_KulJgzguY@6{XiIMixCkFEXLrT_Hl z=TpsV`!*QiG1g%nL-Vmfzr^n@e$n6YhKh@#i3oi=_|^&kpP8`nCG8T$_##(ru08nf z3fd9WM(SoM&d`pji-Q|FPgA(1r*KVA;hvt_vxER|y*j#*WS+Y(oZ_1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{rI=8lJ|wxK;DUmnXkG4Jul#4P;%B$2e77vlF>-cnf@PMW sF(zq@^wf_KW@1qqYxwVKN^10UqPq8E=XBc0#dAh3k?R?Yz>% diff --git a/contextualise.py b/contextualise.py new file mode 100644 index 0000000..47ceeb1 --- /dev/null +++ b/contextualise.py @@ -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 = ""+word+"" + 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) diff --git a/templates/listofwords.html b/templates/listofwords.html index 5ea4adf..ce6b752 100644 --- a/templates/listofwords.html +++ b/templates/listofwords.html @@ -1,3 +1,11 @@ {% extends "layout.html" %} + {% block content %} +{% if cookie is defined %} + {{ cookie }} +{% endif %} + +

lol

+ + {% endblock %}