diff --git a/.DS_Store b/.DS_Store index b8ca954..e41ef18 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/contextualise.py b/contextualise.py index ffb65e9..3afecde 100644 --- a/contextualise.py +++ b/contextualise.py @@ -8,6 +8,8 @@ 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.config.from_object(Config) @@ -23,24 +25,35 @@ app.config.from_object(Config) path = "static/files/" listingfiles= [] #fullpaths listingdirectories = [] #paths +jsonfiles = [] #json files thefile = None #selected file for description now = strftime("%Y-%m-%d_%H:%M:%S", gmtime()) #description time -positioninarray = 0 #counter +positioninarray = 2 #counter + +listofdicts=[] #to be able to import and use json content #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"): + if not name.endswith(".json") and not name.endswith(".DS_Store"): fullpath = os.path.join(path, name) - listingdirectories.append(path) + listingdirectories.append(path[7:]) listingfiles.append(fullpath[7:]) #fullpaths minus static/ - print (path) - print (name) - print (os.path.join(path, name)) + # 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)) + +# print(listofdicts[0]["name"]) #test -dict={} #dict for the form entries +dict = {} #dict for the form entries @app.route("/") def home(): @@ -50,6 +63,15 @@ def home(): def about(): return render_template('about.html') +@app.route('/all/') +def all(): + thefile = listingfiles[positioninarray] + print(listingfiles) + #here i need to json.load each file + print(dict) + return render_template('all.html', file=thefile, listingfiles=listingfiles, jsonfiles=jsonfiles, listofdicts=listofdicts) + + @app.route('/description', methods=['GET', 'POST']) def description(): form = ReusableForm(request.form) @@ -87,6 +109,7 @@ def savepost(): # open with "a" if the file should concatenate content #json file naming gone unique by adding time and date of submission + with open(listingdirectories[positioninarray]+"/"+now+"_data_file.json", "w") as write_file: json.dump(dict, write_file) return "The JSON file is ready." diff --git a/data_file.json b/data_file.json new file mode 100644 index 0000000..d75b1a0 --- /dev/null +++ b/data_file.json @@ -0,0 +1 @@ +{"name": "as", "email": "asd", "friend": "Y", "content": "asd"} \ No newline at end of file diff --git a/forms.py b/forms.py index 44f290a..03018ac 100644 --- a/forms.py +++ b/forms.py @@ -8,4 +8,5 @@ class ReusableForm(Form): email = TextField('Email:',[validators.Required('Please enter your email address.'), validators.Email('Please enter your email address.')]) friend = RadioField('Are you a friend of De Player?', choices = [('Y','Yes'),('NY','Not Yet')]) content = StringField('Description:',[validators.Required('Please enter a description.')]) - submit = SubmitField('Send') \ No newline at end of file + submit = SubmitField('Send') + diff --git a/json_actions.py b/json_actions.py new file mode 100644 index 0000000..d00ed47 --- /dev/null +++ b/json_actions.py @@ -0,0 +1,38 @@ +import json + + +# # to iterate through existing json file and find the correct json file +# def find_json(id): +# get path/to/file + +# return file + +# # +# def save_json(id, name, email, friend, content): +# file +# data = {"id": "path/to/file", "name":,"email":,"friend":,"content":} + +# with open('file.json', 'w') as f: +# json.dump(data, f) + + + + +# def jaction(original, id, name, email, friend, content): +# f = find_json_file(id) +# data = make_dict(f) + +# updated = update_dict(data, name, email, friend, content) +# save_json_file(f, updated) + +# # to find the file with the correct id +# def find_json_file(): +# f = open('file.json', 'w') +# iterate files to find id +# return f + +# # saving the json file +# def save_json_file(name, email, friend, content): +# dict= request.args.get( +# write(file, json.dump(data)) + diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 0000000..c191a5a Binary files /dev/null and b/static/.DS_Store differ diff --git a/static/files/.DS_Store b/static/files/.DS_Store new file mode 100644 index 0000000..72b407c Binary files /dev/null and b/static/files/.DS_Store differ diff --git a/static/files/001/.DS_Store b/static/files/001/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/static/files/001/.DS_Store differ diff --git a/static/files/001/2019-01-22_08:49:43_data_file.json b/static/files/001/2019-01-22_08:49:43_data_file.json new file mode 100644 index 0000000..701e17b --- /dev/null +++ b/static/files/001/2019-01-22_08:49:43_data_file.json @@ -0,0 +1 @@ +{"name": "Canonimouse", "email": "yes@mail.com", "friend": "Y", "content": "The contestants are embracing."} \ No newline at end of file diff --git a/static/files/002/.DS_Store b/static/files/002/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/static/files/002/.DS_Store differ diff --git a/static/files/002/2019-01-15_21:42:00_data_file.json b/static/files/002/2019-01-15_21:42:00_data_file.json deleted file mode 100644 index 92717e4..0000000 --- a/static/files/002/2019-01-15_21:42:00_data_file.json +++ /dev/null @@ -1 +0,0 @@ -{"friend": "NY", "name": "mazouni", "email": "pasdechance", "content": "toute la nuit je pense"} \ No newline at end of file diff --git a/static/files/002/2019-01-20_17:47:03_data_file.json b/static/files/002/2019-01-20_17:47:03_data_file.json new file mode 100644 index 0000000..f3eeaa1 --- /dev/null +++ b/static/files/002/2019-01-20_17:47:03_data_file.json @@ -0,0 +1 @@ +{"name": "Cristina Cochior", "email": "clcochior@gmail.com", "friend": "Y", "content": "Sure"} \ No newline at end of file diff --git a/static/files/002/2019-01-22_09:09:09_data_file.json b/static/files/002/2019-01-22_09:09:09_data_file.json new file mode 100644 index 0000000..9c35830 --- /dev/null +++ b/static/files/002/2019-01-22_09:09:09_data_file.json @@ -0,0 +1 @@ +{"name": "Anonymousse", "email": "bettermail@mail.com", "friend": "Y", "content": "A beach in an Arab-speaking place."} \ No newline at end of file diff --git a/static/files/003/2019-01-22_09:09:52_data_file.json b/static/files/003/2019-01-22_09:09:52_data_file.json new file mode 100644 index 0000000..bc75a85 --- /dev/null +++ b/static/files/003/2019-01-22_09:09:52_data_file.json @@ -0,0 +1 @@ +{"name": "Mysterious", "email": "sound@mail.com", "friend": "Y", "content": "This is a sound file, but I am in a public setting and cannot listen back to it."} \ No newline at end of file diff --git a/templates/all.html b/templates/all.html new file mode 100644 index 0000000..f8bb466 --- /dev/null +++ b/templates/all.html @@ -0,0 +1,64 @@ + + {% extends "layout.html" %} + {% block content %} +
+

These are all the files

+ +
+ {% for filename in listingfiles %} + + {% if filename.lower().endswith(('.png', '.jpg', '.jpeg')) %} + + {% for jsonfile in jsonfiles %} + {% if filename[0:9] == jsonfile[0:9] %} +
+ {{ jsonfile }} +

{{listofdicts[0]["name"]}}
+ {{listofdicts[0]["email"]}}
+ {{listofdicts[0]["friend"]}}
+ {{listofdicts[0]["content"]}}

+
+ {% endif %} + {% endfor %} + + {% elif filename.lower().endswith(('.mp4')) %} + + {% for jsonfile in jsonfiles %} + {% if filename[0:9] == jsonfile[0:9] %} +
+ {{ jsonfile }} +

{{listofdicts[1]["name"]}}
+ {{listofdicts[1]["email"]}}
+ {{listofdicts[1]["friend"]}}
+ {{listofdicts[1]["content"]}}

+
+ {% endif %} + {% endfor %} + + {% elif filename.lower().endswith(('.mp3')) %} + + {% for jsonfile in jsonfiles %} + {% if filename[0:9] == jsonfile[0:9] %} +
+ {{ jsonfile }} +

{{listofdicts[2]["name"]}}
+ {{listofdicts[2]["email"]}}
+ {{listofdicts[2]["friend"]}}
+ {{listofdicts[2]["content"]}}

+
+ {% endif %} + {% endfor %} + {% endif %} + + {% endfor %} +
+
+ {% endblock %} + + diff --git a/templates/layout.html b/templates/layout.html index dd68974..8caf8e6 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -14,6 +14,7 @@
  • Home
  • About
  • Form
  • +
  • All files