diff --git a/README.md b/README.md index 8a780f8..804fb23 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# PushingScores - +# Pushing Scores +## Initial experiments for the Pushing Scores project diff --git a/__pycache__/config.cpython-36.pyc b/__pycache__/config.cpython-36.pyc new file mode 100644 index 0000000..cf0cfca Binary files /dev/null and b/__pycache__/config.cpython-36.pyc differ diff --git a/__pycache__/contextualise.cpython-36.pyc b/__pycache__/contextualise.cpython-36.pyc new file mode 100644 index 0000000..fc0b373 Binary files /dev/null and b/__pycache__/contextualise.cpython-36.pyc differ diff --git a/__pycache__/forms.cpython-36.pyc b/__pycache__/forms.cpython-36.pyc new file mode 100644 index 0000000..9aa3e7e Binary files /dev/null and b/__pycache__/forms.cpython-36.pyc differ diff --git a/__pycache__/json_actions.cpython-36.pyc b/__pycache__/json_actions.cpython-36.pyc new file mode 100644 index 0000000..14d39b0 Binary files /dev/null and b/__pycache__/json_actions.cpython-36.pyc differ diff --git a/__pycache__/startform.cpython-36.pyc b/__pycache__/startform.cpython-36.pyc new file mode 100644 index 0000000..9dbc1de Binary files /dev/null and b/__pycache__/startform.cpython-36.pyc differ diff --git a/config.py b/config.py new file mode 100644 index 0000000..242d1b0 --- /dev/null +++ b/config.py @@ -0,0 +1,4 @@ +import os + +class Config(object): + SECRET_KEY = os.environ.get('SECRET_KEY') or 'you-will-never-guess' \ No newline at end of file diff --git a/contextualise.py b/contextualise.py new file mode 100644 index 0000000..6091f79 --- /dev/null +++ b/contextualise.py @@ -0,0 +1,124 @@ +from flask import Flask, url_for, render_template, Markup, redirect, request, flash +from flask import session as login_session +from flask_wtf import FlaskForm +from wtforms.validators import DataRequired +from wtforms import Form, TextField, TextAreaField, BooleanField, validators, StringField, SubmitField +from forms import ReusableForm +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) + + +#### THE CHECKBOX RESULT DOESNT GET RECORDED TO THE JSON FILE +#### FULL LOOP WITH FILE AND RELOADING THE FORM WITH NEXT FILE IN THE ARRAY HAS TO BE MADE +#### OPTIONS TO SWITCH BETWEEN FILES NEED TO BE AVAILABLE +#### MAYBE CONFIRMATION BEFORE JSON IS RECORDED TO FORCE PEOPLE TO DOUBLE THINK + + +# setting variables for holding paths, folder names and the one file for description +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 = 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") and not name.endswith(".DS_Store"): + fullpath = os.path.join(path, name) + listingdirectories.append(path) + listingfiles.append(fullpath[7:]) #fullpaths minus static/ + # 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 + +@app.route("/") +def home(): + return render_template('home.html') + +@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', methods=['GET', 'POST']) +def description(): + form = ReusableForm(request.form) +#pick a file but that will be done an other way later + thefile = listingfiles[positioninarray] #select one file from fullpath minus static/ + +# assigning html tag on the basis of extension, to be finished when all the files have been sent + if thefile.lower().endswith(('.png', '.jpg', '.jpeg')): + thefile = Markup('') + + #if sound + elif thefile.lower().endswith(('.mp3')): + thefile = Markup('''''') + #ifvid to be added + elif thefile.lower().endswith(('.mp4')): + thefile = Markup(''' ''') + + print (form.errors) + if request.method == 'POST' and form.validate(): + return 'Success!' + # return render_template('description.html', form=form, file=thefile, listingdirectories=listingdirectories, listingfiles=listingfiles) + return render_template('description.html', form=form, file=thefile) + + +@app.route('/get-data', methods=['GET', 'POST']) +def savepost(): + if request.method=='POST': + dict={'id':listingdirectories[positioninarray][13:],'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']} + # 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." + #throw description and next item, wee need to iterate through the files + + else: + return "Error" + + +if __name__ == '__main__': + app.run(debug=True) diff --git a/contextualiseold.py b/contextualiseold.py new file mode 100644 index 0000000..e1ba403 --- /dev/null +++ b/contextualiseold.py @@ -0,0 +1,45 @@ +from flask import Flask, url_for, render_template, Markup, redirect, request, flash +from flask import session as login_session +from flask_wtf import FlaskForm +from wtforms.validators import DataRequired +from wtforms import Form, TextField, TextAreaField, BooleanField, validators, StringField, SubmitField +from forms import ReusableForm +from config import Config +import json + +app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") +app.config.from_object(Config) + +@app.route("/") +def home(): + return render_template('home.html') + +@app.route('/about/') +def about(): + return render_template('about.html') + +@app.route('/description', methods=['GET', 'POST']) +def description(): + form = ReusableForm(request.form) + print (form.errors) + if request.method == 'POST' and form.validate(): + return 'Success!' + return render_template('description.html', form=form) + + +dict={} + +@app.route('/get-data', methods=['GET', 'POST']) +def savepost(): + if request.method=='POST': + dict={'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']} + # open with "a" if the file should concatenate content + with open("data_file.json", "w") as write_file: + json.dump(dict, write_file) + return "The JSON file is ready." + else: + return "Error" + + +if __name__ == '__main__': + app.run(debug=True) 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 new file mode 100644 index 0000000..03018ac --- /dev/null +++ b/forms.py @@ -0,0 +1,12 @@ +from flask_wtf import Form +from wtforms import TextField, IntegerField, TextAreaField, SubmitField, RadioField, SelectField, StringField + +from wtforms import validators, ValidationError + +class ReusableForm(Form): + name = TextField('Name:', [validators.Required('Please enter your name.')]) + 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') + 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/startform.py b/startform.py new file mode 100644 index 0000000..a5c66ee --- /dev/null +++ b/startform.py @@ -0,0 +1,34 @@ +from wtforms import Form, TextField, BooleanField, StringField, SubmitField, validators +from flask import Flask, url_for, render_template, Markup, redirect, request, flash +from flask import session as login_session +from forms import ReusableForm +from config import Config +# import json_actions +import json + +app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates") +app.config.from_object(Config) + + +@app.route('/', methods=['GET', 'POST']) +def description(): + form = ReusableForm(request.form) + print (form.errors) + if request.method == 'POST' and form.validate(): + return 'Success!' + return render_template('description-prev.html', form=form) +if __name__ == '__main__': + app.run(debug = True) + +dict={} + +@app.route('/get-data', methods=['GET', 'POST']) +def savepost(): + if request.method=='POST': + dict={'name':request.form['name'],'email':request.form['email'],'friend':request.form['friend'],'content':request.form['content']} + # open with "a" if the file should concatenate content + with open("data_file.json", "w") as write_file: + json.dump(dict, write_file) + return "The JSON file is ready." + else: + return "Error" \ No newline at end of file diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 0000000..4f3d22f Binary files /dev/null and b/static/.DS_Store differ diff --git a/static/css/main.css b/static/css/main.css new file mode 100644 index 0000000..c6cc167 --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,4 @@ +body{ + background: lavender; + color:blue; +} \ No newline at end of file diff --git a/static/files/.DS_Store b/static/files/.DS_Store new file mode 100644 index 0000000..03c4e29 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..659b428 --- /dev/null +++ b/static/files/001/2019-01-22_08:49:43_data_file.json @@ -0,0 +1 @@ +{"id":"001","name": "Canonimouse", "email": "yes@mail.com", "friend": "Y", "content": "The contestants are embracing."} \ No newline at end of file diff --git a/static/files/001/DwySYC4X4AESeRh.jpg b/static/files/001/DwySYC4X4AESeRh.jpg new file mode 100644 index 0000000..e0ecf5d Binary files /dev/null and b/static/files/001/DwySYC4X4AESeRh.jpg differ 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-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..2340151 --- /dev/null +++ b/static/files/002/2019-01-20_17:47:03_data_file.json @@ -0,0 +1 @@ +{"id":"002","name": "XYZ", "email": "yesihave@one.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..b3e84db --- /dev/null +++ b/static/files/002/2019-01-22_09:09:09_data_file.json @@ -0,0 +1 @@ +{"id":"002","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/002/YvWL9feSIXyMC2il.mp4 b/static/files/002/YvWL9feSIXyMC2il.mp4 new file mode 100644 index 0000000..46aecc6 Binary files /dev/null and b/static/files/002/YvWL9feSIXyMC2il.mp4 differ diff --git a/static/files/003/.DS_Store b/static/files/003/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/static/files/003/.DS_Store differ diff --git a/static/files/003/2019-01-23_10:38:26_data_file.json b/static/files/003/2019-01-23_10:38:26_data_file.json new file mode 100644 index 0000000..ddc3762 --- /dev/null +++ b/static/files/003/2019-01-23_10:38:26_data_file.json @@ -0,0 +1 @@ +{"id": "003", "name": "Yes", "email": "sure@whynot.com", "friend": "Y", "content": "A sound file."} \ No newline at end of file diff --git a/static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3 b/static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3 new file mode 100644 index 0000000..45e52c0 Binary files /dev/null and b/static/files/003/Titanic drawing rose meme.-jWcZ2oNAKB4.mp3 differ diff --git a/templates/.DS_Store b/templates/.DS_Store new file mode 100644 index 0000000..752d06d Binary files /dev/null and b/templates/.DS_Store differ diff --git a/templates/about.html b/templates/about.html new file mode 100644 index 0000000..ceb5c38 --- /dev/null +++ b/templates/about.html @@ -0,0 +1,7 @@ + {% extends "layout.html" %} + {% block content %} +
+

About me

+

This is a portfolio site about anything that can be put in a portfolio.

+
+ {% endblock %} diff --git a/templates/all.html b/templates/all.html new file mode 100644 index 0000000..56b36d9 --- /dev/null +++ b/templates/all.html @@ -0,0 +1,75 @@ + + {% extends "layout.html" %} + {% block content %} +
+

These are all the files

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

{% for key, value in dict.items() %} + {{key}}: {{value}}
+ {% endfor %}

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

{% for key, value in dict.items() %} + {{key}}: {{value}}
+ {% endfor %}

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

{% for key, value in dict.items() %} + {{key}}: {{value}}
+ {% endfor %}

+ {% endif %} + {% endfor %} +
+ {% break %} + {% endif %} + {% endfor %} + {% endif %} + + {% endfor %} +
+
+ {% endblock %} + + diff --git a/templates/description.html b/templates/description.html new file mode 100644 index 0000000..bb2fbfa --- /dev/null +++ b/templates/description.html @@ -0,0 +1,35 @@ +{% extends "layout.html" %} +{% block content %} +
+

Write something very interesting here.

+ + +

{{ file }}

+ + + + + + {% for message in form.name.errors %} +
{{ message }}
+ {% endfor %} + +
+
+ {{ form.hidden_tag() }} +
{{ form.name.label }} {{ form.name }}
+
{{ form.email.label }} {{ form.email }}
+
{{ form.friend.label }} {{ form.friend }}
+
{{ form.content.label }} {{ form.content }}
+
{{ form.submit }}
+
+
+
+ {% endblock %} diff --git a/templates/home.html b/templates/home.html new file mode 100644 index 0000000..308dbe0 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,7 @@ +{% extends "layout.html" %} + {% block content %} +
+

THIS IS THE HOME PAGE

+

This website was built with Python via the Flask framework.

+
+ {% endblock %} \ No newline at end of file diff --git a/templates/layout.html b/templates/layout.html new file mode 100644 index 0000000..8caf8e6 --- /dev/null +++ b/templates/layout.html @@ -0,0 +1,27 @@ + + + + + PARTOUT TITRE PARTOUT + + + +
+
+

SUPERB

+ +
+
+
+ {% block content %} + {% endblock %} +
+ + \ No newline at end of file