diff --git a/erbold/Python/Django/cool/apps/__init__.py b/erbold/Python/Django/cool/apps/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/erbold/Python/Django/cool/apps/first_app/__init__.py b/erbold/Python/Django/cool/apps/first_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/erbold/Python/Django/cool/apps/first_app/admin.py b/erbold/Python/Django/cool/apps/first_app/admin.py new file mode 100644 index 0000000..13be29d --- /dev/null +++ b/erbold/Python/Django/cool/apps/first_app/admin.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib import admin + +# Register your models here. diff --git a/erbold/Python/Django/cool/apps/first_app/apps.py b/erbold/Python/Django/cool/apps/first_app/apps.py new file mode 100644 index 0000000..70b2f8d --- /dev/null +++ b/erbold/Python/Django/cool/apps/first_app/apps.py @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.apps import AppConfig + + +class FirstAppConfig(AppConfig): + name = 'first_app' diff --git a/erbold/Python/Django/cool/apps/first_app/migrations/__init__.py b/erbold/Python/Django/cool/apps/first_app/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/erbold/Python/Django/cool/apps/first_app/models.py b/erbold/Python/Django/cool/apps/first_app/models.py new file mode 100644 index 0000000..1dfab76 --- /dev/null +++ b/erbold/Python/Django/cool/apps/first_app/models.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models + +# Create your models here. diff --git a/erbold/Python/Django/cool/apps/first_app/tests.py b/erbold/Python/Django/cool/apps/first_app/tests.py new file mode 100644 index 0000000..5982e6b --- /dev/null +++ b/erbold/Python/Django/cool/apps/first_app/tests.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.test import TestCase + +# Create your tests here. diff --git a/erbold/Python/Django/cool/apps/first_app/urls.py b/erbold/Python/Django/cool/apps/first_app/urls.py new file mode 100644 index 0000000..e575182 --- /dev/null +++ b/erbold/Python/Django/cool/apps/first_app/urls.py @@ -0,0 +1,9 @@ +from django.conf.urls import url +from . import views # This line is new! + +urlpatterns = [ + url(r'^$', views.index), # This line has changed! + url(r'^new$', views.new), + url(r'^(?P\d+)$', views.show), + # url(r'^$', views.index) +] \ No newline at end of file diff --git a/erbold/Python/Django/cool/apps/first_app/views.py b/erbold/Python/Django/cool/apps/first_app/views.py new file mode 100644 index 0000000..c1a3a5d --- /dev/null +++ b/erbold/Python/Django/cool/apps/first_app/views.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from django.shortcuts import render, HttpResponse, redirect +# the index function is called when root is visited +def index(request): + response = "placeholder to display a new form to create a new blog" + return HttpResponse(response) + +def new(request): + response = "placeholder to display a new form to create a new boogy" + return HttpResponse(response) + +def show(request, number): + response = number + return HttpResponse(response) + +# def index(request): +# response = "Hello, I am your 2nd request!" +# return HttpResponse(response) + +# Create your views here. diff --git a/erbold/Python/Django/cool/cool/__init__.py b/erbold/Python/Django/cool/cool/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/erbold/Python/Django/cool/cool/settings.py b/erbold/Python/Django/cool/cool/settings.py new file mode 100644 index 0000000..2d41a42 --- /dev/null +++ b/erbold/Python/Django/cool/cool/settings.py @@ -0,0 +1,121 @@ +""" +Django settings for cool project. + +Generated by 'django-admin startproject' using Django 1.11.7. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.11/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'wew74i+x1(fl0qervmx#+jah+@8@vq_d)nsspp6&-ib4u1husm' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'apps.first_app', + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'cool.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'cool.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/1.11/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/1.11/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.11/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/erbold/Python/Django/cool/cool/urls.py b/erbold/Python/Django/cool/cool/urls.py new file mode 100644 index 0000000..f560c5b --- /dev/null +++ b/erbold/Python/Django/cool/cool/urls.py @@ -0,0 +1,21 @@ +"""cool URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/1.11/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.conf.urls import url, include + 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) +""" +from django.conf.urls import url, include +from django.contrib import admin + +urlpatterns = [ + url(r'^', include('apps.first_app.urls')) +] diff --git a/erbold/Python/Django/cool/cool/wsgi.py b/erbold/Python/Django/cool/cool/wsgi.py new file mode 100644 index 0000000..3e61450 --- /dev/null +++ b/erbold/Python/Django/cool/cool/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for cool project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/1.11/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cool.settings") + +application = get_wsgi_application() diff --git a/erbold/Python/Django/cool/db.sqlite3 b/erbold/Python/Django/cool/db.sqlite3 new file mode 100644 index 0000000..b9d314a Binary files /dev/null and b/erbold/Python/Django/cool/db.sqlite3 differ diff --git a/erbold/Python/Django/cool/manage.py b/erbold/Python/Django/cool/manage.py new file mode 100644 index 0000000..290ad5a --- /dev/null +++ b/erbold/Python/Django/cool/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cool.settings") + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise + execute_from_command_line(sys.argv) diff --git a/erbold/Python/Flask/counter/server.py b/erbold/Python/Flask/counter/server.py new file mode 100644 index 0000000..2127555 --- /dev/null +++ b/erbold/Python/Flask/counter/server.py @@ -0,0 +1,12 @@ +from flask import Flask, render_template, request, redirect, session +app = Flask(__name__) +app.secret_key = 'ThisIsSecret' + +@app.route('/') +def index(): + session['count'] += 1 + return render_template('index.html', count=session['count']) + + + +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/Flask/counter/templates/index.html b/erbold/Python/Flask/counter/templates/index.html new file mode 100644 index 0000000..a3af626 --- /dev/null +++ b/erbold/Python/Flask/counter/templates/index.html @@ -0,0 +1,11 @@ + + + + Counter assignment + + +

Counter

+

{{session['count']}}

+ + + \ No newline at end of file diff --git a/erbold/Python/Flask/counter/templates/user.html b/erbold/Python/Flask/counter/templates/user.html new file mode 100644 index 0000000..a3f5128 --- /dev/null +++ b/erbold/Python/Flask/counter/templates/user.html @@ -0,0 +1,10 @@ + + + Form Test Show + + +

User:

+

{{session['name']}}

+

{{session['email']}}

+ + \ No newline at end of file diff --git a/erbold/Python/Flask/dissNinja/dissNinja.py b/erbold/Python/Flask/dissNinja/dissNinja.py new file mode 100644 index 0000000..0c20169 --- /dev/null +++ b/erbold/Python/Flask/dissNinja/dissNinja.py @@ -0,0 +1,29 @@ +from flask import Flask, render_template, redirect, request, session +app = Flask(__name__) +app.secret_key = random.randit() + +@app.route("/") +def index(): + return render_template("index.html") + + +@app.route("/ninjas") +def group(): + + return render_template("group.html") + +@app.route("/ninjas/") +def colors(color): + + if color == "blue": + return render_template("blue.html") + elif color == "red": + return render_template("red.html") + elif color == "orange": + return render_template("orange.html") + elif color == "purple": + return render_template("purple.html") + elif color != "red" "blue" "orange" "purple": + return render_template("ninjas.html") + +app.run(debug=True) diff --git a/erbold/Python/Flask/dissNinja/static/donatello.jpg b/erbold/Python/Flask/dissNinja/static/donatello.jpg new file mode 100644 index 0000000..8912292 Binary files /dev/null and b/erbold/Python/Flask/dissNinja/static/donatello.jpg differ diff --git a/erbold/Python/Flask/dissNinja/static/leonardo.jpg b/erbold/Python/Flask/dissNinja/static/leonardo.jpg new file mode 100644 index 0000000..c049cfd Binary files /dev/null and b/erbold/Python/Flask/dissNinja/static/leonardo.jpg differ diff --git a/erbold/Python/Flask/dissNinja/static/michelangelo.jpg b/erbold/Python/Flask/dissNinja/static/michelangelo.jpg new file mode 100644 index 0000000..4ad75d0 Binary files /dev/null and b/erbold/Python/Flask/dissNinja/static/michelangelo.jpg differ diff --git a/erbold/Python/Flask/dissNinja/static/notapril.jpg b/erbold/Python/Flask/dissNinja/static/notapril.jpg new file mode 100644 index 0000000..39b2f0a Binary files /dev/null and b/erbold/Python/Flask/dissNinja/static/notapril.jpg differ diff --git a/erbold/Python/Flask/dissNinja/static/raphael.jpg b/erbold/Python/Flask/dissNinja/static/raphael.jpg new file mode 100644 index 0000000..57fb2a3 Binary files /dev/null and b/erbold/Python/Flask/dissNinja/static/raphael.jpg differ diff --git a/erbold/Python/Flask/dissNinja/static/tmnt.png b/erbold/Python/Flask/dissNinja/static/tmnt.png new file mode 100644 index 0000000..941c82e Binary files /dev/null and b/erbold/Python/Flask/dissNinja/static/tmnt.png differ diff --git a/erbold/Python/Flask/dissNinja/templates/blue.html b/erbold/Python/Flask/dissNinja/templates/blue.html new file mode 100644 index 0000000..3a43536 --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/blue.html @@ -0,0 +1 @@ + diff --git a/erbold/Python/Flask/dissNinja/templates/group.html b/erbold/Python/Flask/dissNinja/templates/group.html new file mode 100644 index 0000000..0d91dcb --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/group.html @@ -0,0 +1 @@ + diff --git a/erbold/Python/Flask/dissNinja/templates/index.html b/erbold/Python/Flask/dissNinja/templates/index.html new file mode 100644 index 0000000..bad9c66 --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/index.html @@ -0,0 +1,3 @@ +

+ No Ninjas Here! +

\ No newline at end of file diff --git a/erbold/Python/Flask/dissNinja/templates/ninjas.html b/erbold/Python/Flask/dissNinja/templates/ninjas.html new file mode 100644 index 0000000..3a9c7d6 --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/ninjas.html @@ -0,0 +1 @@ + diff --git a/erbold/Python/Flask/dissNinja/templates/orange.html b/erbold/Python/Flask/dissNinja/templates/orange.html new file mode 100644 index 0000000..3322862 --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/orange.html @@ -0,0 +1 @@ + diff --git a/erbold/Python/Flask/dissNinja/templates/purple.html b/erbold/Python/Flask/dissNinja/templates/purple.html new file mode 100644 index 0000000..03c8d9a --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/purple.html @@ -0,0 +1 @@ + diff --git a/erbold/Python/Flask/dissNinja/templates/red.html b/erbold/Python/Flask/dissNinja/templates/red.html new file mode 100644 index 0000000..05bbcb9 --- /dev/null +++ b/erbold/Python/Flask/dissNinja/templates/red.html @@ -0,0 +1 @@ + diff --git a/erbold/Python/Flask/dojoSurvey/dojoSurvey.py b/erbold/Python/Flask/dojoSurvey/dojoSurvey.py index 146159b..61d963f 100644 --- a/erbold/Python/Flask/dojoSurvey/dojoSurvey.py +++ b/erbold/Python/Flask/dojoSurvey/dojoSurvey.py @@ -24,11 +24,7 @@ def index(): @app.route("/result", methods = ['POST']) def result(): - - First_name = request.form['fname'] - Last_name = request.form['lname'] - print First_name - print Last_name + return render_template("results.html", First_name = request.form['fname'], Last_name = request.form['lname']) app.run(debug=True) diff --git a/erbold/Python/Flask/numberGame/server.py b/erbold/Python/Flask/numberGame/server.py new file mode 100644 index 0000000..18544f0 --- /dev/null +++ b/erbold/Python/Flask/numberGame/server.py @@ -0,0 +1,48 @@ +from flask import Flask, flash, render_template, request, redirect, session +import random + +app = Flask(__name__) +app.secret_key = 'ThisIsSecret' + +def setSession(): + session['num'] = random.randint(1,100) + +@app.route('/') +def index(): + if session.get('num') == None: + setSession() + else: + pass + print session['num'] + return render_template('index.html') + +@app.route('/guess', methods=['POST']) +def checkNumber(): + error = None + success = None + guess = request.form['guess'] + if request.method == 'POST': + if guess.isdigit(): + numguess = int(guess) + if numguess == session['num']: + flash('Correct', 'success') + return redirect('/') + elif numguess > session['num']: + flash('Too high', 'error') + else: + flash('Too low', 'error') + else: + flash('Not a valid guess', 'error') + elif isinstance(guess, str): + flash('Not a valid guess', 'error') + else: + flash('Not a valid guess', 'error') + + return redirect('/') + +@app.route('/reset', methods=['GET', 'POST']) +def reset(): + setSession() + return redirect('/') + +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/Flask/numberGame/static/guess.html b/erbold/Python/Flask/numberGame/static/guess.html new file mode 100644 index 0000000..2798eb4 --- /dev/null +++ b/erbold/Python/Flask/numberGame/static/guess.html @@ -0,0 +1,23 @@ + + + Great Number Game + + +

Welcome to the Great Number Game

+

I am thinking of a number between 1 and 100

+

Take a guess

+
+
+ +
+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} + + \ No newline at end of file diff --git a/erbold/Python/Flask/numberGame/templates/index.html b/erbold/Python/Flask/numberGame/templates/index.html new file mode 100644 index 0000000..99e5ab1 --- /dev/null +++ b/erbold/Python/Flask/numberGame/templates/index.html @@ -0,0 +1,38 @@ + + + + Great Number Game + + +

Welcome to the Great Number Game

+

I am thinking of a number between 1 and 100

+

Take a guess

+
+
+ +
+ {% with errors = get_flashed_messages(category_filter=["error"]) %} + {% if errors %} +
+ {%- for msg in errors %} +

{{ msg }}

+ {% endfor -%} +
+ {% endif %} + {% endwith %} + + {% with successes = get_flashed_messages(category_filter=["success"]) %} + {% if successes %} +
+ {%- for msg in successes %} +

{{ msg }}

+ {% endfor -%} +
+ +
+
+ {% endif %} + {% endwith %} + + + \ No newline at end of file diff --git a/erbold/Python/Flask/numberGame/templates/yup.html b/erbold/Python/Flask/numberGame/templates/yup.html new file mode 100644 index 0000000..a1bd930 --- /dev/null +++ b/erbold/Python/Flask/numberGame/templates/yup.html @@ -0,0 +1,54 @@ + + + + + Great Number Game + + +

Welcome to the Great Number Game

+

I am thinking of a number between 1 and 100

+

Take a guess

+
+
+ +
+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} + + + + +h1 { + text-align: center; +} + +p { + text-align: center; +} + +form { + text-align: center; +} + +.flashes { + box-sizing: border-box; + padding: 50px; + width:300px; + margin: 0 auto; + margin-top: 30px; +} + +.error { + background: red; +} + +.success { + background: green; +} \ No newline at end of file diff --git a/erbold/Python/Flask/regisForm/regisForm.py b/erbold/Python/Flask/regisForm/regisForm.py new file mode 100644 index 0000000..5b6afa8 --- /dev/null +++ b/erbold/Python/Flask/regisForm/regisForm.py @@ -0,0 +1,61 @@ +from flask import Flask, flash, render_template, request, redirect, session +import re + +emailRegex = re.compile(r'^[a-zA-Z0-9\.\+_-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]*$') +# passwordRegex = re.compile(r'^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$') + +app = Flask(__name__) +app.secret_key = 'dope' + +def countLetters(word): + count = 0 + for c in word: + count += 1 + return count + +@app.route("/") +def index(): + + # if session.get('num') == None: + # setSession() + # else: + # pass + # print session['num'] + return render_template("index.html") + + +@app.route("/answer", methods = ['POST']) +def result(): + First_name = request.form['fname'] + Last_name = request.form['lname'] + Email = request.form['email'] + Password = request.form['password'] + Conf_Password = request.form['password2'] + + if First_name == '' or Last_name == '' or Email == '' or Password == ''or Conf_Password == '': + flash('error blank', 'error') + return redirect('/') + + if any(char.isdigit() for char in Last_name) == True or any(char.isdigit() for char in First_name) == True: + flash('Name cant have numbers', 'error') + return redirect('/') + + session['password'] = request.form['password'] + password = countLetters(session['password']) + print password + if password < 9: + flash('length error', 'error') + return redirect('/') + + if not emailRegex.match(Email): + flash("Invalid Email Address!", 'error') + return redirect('/') + + if Password != Conf_Password: + flash('Password does not match', 'error') + return redirect('/') + + return render_template("answer.html", First_name = First_name, Last_name = Last_name, Email = Email, Password = Password, Conf_Password = Conf_Password) + return redirect('/') + +app.run(debug=True) diff --git a/erbold/Python/Flask/regisForm/templates/answer.html b/erbold/Python/Flask/regisForm/templates/answer.html new file mode 100644 index 0000000..2657e63 --- /dev/null +++ b/erbold/Python/Flask/regisForm/templates/answer.html @@ -0,0 +1,13 @@ + + + Template Test + + +

My name is {{First_name}}

+

My name is {{Last_name}}

+

Email: {{Email}}

+

My password is {{Password}}

+

My password confirmation is {{Conf_Password}}

+ + + \ No newline at end of file diff --git a/erbold/Python/Flask/regisForm/templates/index.html b/erbold/Python/Flask/regisForm/templates/index.html new file mode 100644 index 0000000..3546cfb --- /dev/null +++ b/erbold/Python/Flask/regisForm/templates/index.html @@ -0,0 +1,29 @@ + + + + + + + +
+ First name:
+ Last name:
+ Email:
+ Password:
+ Confirm Passw.:
+ +
+ + {% with errors = get_flashed_messages(category_filter=["error"]) %} + {% if errors %} +
+ {%- for msg in errors %} +

{{ msg }}

+ {% endfor %} +
+ {% endif %} + {% endwith %} + + + + \ No newline at end of file diff --git a/erbold/Python/Flask/surveyValid/server.py b/erbold/Python/Flask/surveyValid/server.py new file mode 100644 index 0000000..9df675f --- /dev/null +++ b/erbold/Python/Flask/surveyValid/server.py @@ -0,0 +1,48 @@ +from flask import Flask, flash, render_template, request, redirect, session + +app = Flask(__name__) +app.secret_key = 'dope' + +def countLetters(word): + count = 0 + for c in word: + count += 1 + return count + +@app.route("/") +def index(): + + # if session.get('num') == None: + # setSession() + # else: + # pass + # print session['num'] + return render_template("index.html") + + +@app.route("/answer", methods = ['POST']) +def result(): + First_name = request.form['fname'] + Last_name = request.form['lname'] + Comment = request.form['comment'] + + if First_name == '': + flash('error blank', 'error') + return redirect('/') + + if Last_name == '': + flash('error blank', 'error') + return redirect('/') + + session['comment'] = request.form['comment'] + comment = countLetters(session['comment']) + print comment + if comment > 120: + flash('length error', 'error') + return redirect('/') + + + return render_template("answer.html", First_name = First_name, Last_name = Last_name, Comment = Comment) + return redirect('/') + +app.run(debug=True) diff --git a/erbold/Python/Flask/surveyValid/templates/answer.html b/erbold/Python/Flask/surveyValid/templates/answer.html new file mode 100644 index 0000000..1aae5bf --- /dev/null +++ b/erbold/Python/Flask/surveyValid/templates/answer.html @@ -0,0 +1,11 @@ + + + Template Test + + +

My name is {{First_name}}

+

My name is {{Last_name}}

+

Comment: {{Comment}}

+ + + \ No newline at end of file diff --git a/erbold/Python/Flask/surveyValid/templates/index.html b/erbold/Python/Flask/surveyValid/templates/index.html new file mode 100644 index 0000000..f86dcaa --- /dev/null +++ b/erbold/Python/Flask/surveyValid/templates/index.html @@ -0,0 +1,27 @@ + + + + + + + +
+ First name:
+ Last name:
+ Comment:
+ +
+ + {% with errors = get_flashed_messages(category_filter=["error"]) %} + {% if errors %} +
+ {%- for msg in errors %} +

{{ msg }}

+ {% endfor %} +
+ {% endif %} + {% endwith %} + + + + \ No newline at end of file diff --git a/erbold/Python/MySQL/Blogs/blogs.mwb b/erbold/Python/MySQL/Blogs/blogs.mwb new file mode 100644 index 0000000..89d9e48 Binary files /dev/null and b/erbold/Python/MySQL/Blogs/blogs.mwb differ diff --git a/erbold/Python/MySQL/Books/Books.mwb b/erbold/Python/MySQL/Books/Books.mwb new file mode 100644 index 0000000..cd36ccc Binary files /dev/null and b/erbold/Python/MySQL/Books/Books.mwb differ diff --git a/erbold/Python/MySQL/Countries/countries.sql b/erbold/Python/MySQL/Countries/countries.sql new file mode 100644 index 0000000..61f9fb5 --- /dev/null +++ b/erbold/Python/MySQL/Countries/countries.sql @@ -0,0 +1,51 @@ +SELECT countries.name, languages.language, languages.percentage +FROM countries + JOIN languages ON countries.id = languages.country_id +WHERE languages.language = 'Slovene' +ORDER BY languages.percentage DESC; + + +SELECT countries.name, COUNT(cities.id) as num_cities +FROM countries + JOIN cities ON countries.id = cities.country_id +GROUP BY countries.id +ORDER BY num_cities DESC; + +SELECT cities.name, cities.population +FROM countries + JOIN cities ON countries.id = cities.country_id +WHERE countries.name = 'Mexico' and cities.population > 500000 +ORDER BY cities.population DESC; + + +SELECT countries.name, languages.language, languages.percentage +FROM countries + JOIN languages on countries.id = languages.country_id +WHERE languages.percentage > 89 +ORDER BY languages.percentage DESC; + + +SELECT countries.name, countries.surface_area, countries.population +FROM countries +WHERE countries.surface_area > 501 AND countries.population > 100000; + + +SELECT countries.name, countries.government_form, countries.capital +FROM countries +WHERE countries.government_form = 'Constitutional Monarchy' + AND countries.life_expectancy > 75 + AND countries.capital > 200; + + +SELECT countries.name, cities.name, cities.district, cities.population +FROM countries + JOIN cities ON countries.id = cities.country_id +WHERE countries.name = 'Argentina' + AND cities.district = 'Buenos Aires' + AND cities.population > 500000; + + +SELECT countries.region, COUNT(countries.id) AS num_countries +FROM countries +GROUP BY countries.region +ORDER BY num_countries DESC; \ No newline at end of file diff --git a/erbold/Python/MySQL/Dashboard/dashboard.mwb b/erbold/Python/MySQL/Dashboard/dashboard.mwb new file mode 100644 index 0000000..3da1daa Binary files /dev/null and b/erbold/Python/MySQL/Dashboard/dashboard.mwb differ diff --git a/erbold/Python/MySQL/lead_gen/lead_gen.mwb b/erbold/Python/MySQL/lead_gen/lead_gen.mwb new file mode 100644 index 0000000..c0cc27a Binary files /dev/null and b/erbold/Python/MySQL/lead_gen/lead_gen.mwb differ diff --git a/erbold/Python/MySQL/productcat.mwb b/erbold/Python/MySQL/productcat.mwb new file mode 100644 index 0000000..86659e1 Binary files /dev/null and b/erbold/Python/MySQL/productcat.mwb differ diff --git a/erbold/Python/MySQL/sakila/sakila.sql b/erbold/Python/MySQL/sakila/sakila.sql new file mode 100644 index 0000000..8d5f6ec --- /dev/null +++ b/erbold/Python/MySQL/sakila/sakila.sql @@ -0,0 +1,72 @@ +SELECT customer.first_name, customer.last_name, customer.email, address.address, address.address2, address.postal_code +FROM customer + JOIN address ON customer.address_id = address.address_id +WHERE city_id = 312; + + +SELECT film.title, film.description, film.release_year, film.rating, film.special_features, category.name +FROM film + JOIN film_category ON film.film_id = film_category.film_id + JOIN category ON film_category.category_id = category.category_id +WHERE category.name = 'Comedy'; + + + +SELECT actor.actor_id, CONCAT(actor.first_name, ' ', actor.last_name) AS actor, title, film.description, film.release_year +FROM film + JOIN film_actor ON film.film_id = film_actor.film_id + JOIN actor ON film_actor.actor_id = actor.actor_id +WHERE actor.actor_id = 5; + + + +SELECT customer.first_name, customer.last_name, customer.email, address.address +FROM customer + JOIN address ON customer.address_id = address.address_id + JOIN city ON address.city_id = city.city_id +WHERE customer.store_id = 1 + AND city.city_id IN (1, 42, 312, 459); + + + +SELECT film.title, film.description, film.release_year, film.rating, film.special_features +FROM film + JOIN film_actor ON film.film_id = film_actor.film_id + JOIN actor ON film_actor.actor_id = actor.actor_id +WHERE film.rating = 'G' + AND film.special_features LIKE '%behind the scenes%' + AND actor.actor_id = 15; + + + + + +SELECT film.film_id, film.title, actor.actor_id, CONCAT(actor.first_name, ' ', actor.last_name) AS actor_name +FROM film + JOIN film_actor ON film.film_id = film_actor.film_id + JOIN actor ON film_actor.actor_id = actor.actor_id +WHERE film.film_id = 369; + + + + + +SELECT film.title, film.description, film.release_year, film.rating, film.special_features, category.name AS genre +FROM category + JOIN film_category ON category.category_id = film_category.category_id + JOIN film ON film_category.film_id = film.film_id +WHERE film.rental_rate = 2.99 + AND category.name = 'Drama'; + + + + +SELECT film.title, film.description, film.release_year, film.rating, film.special_features, category.name AS genre, actor.first_name, actor.last_name +FROM actor + JOIN film_actor ON actor.actor_id = film_actor.actor_id + JOIN film ON film_actor.film_id = film.film_id + JOIN film_category ON film.film_id = film_category.film_id + JOIN category ON film_category.category_id = category.category_id +WHERE actor.first_name = 'Sandra' + AND actor.last_name = 'Kilmer' + AND category.name = 'Action'; diff --git a/erbold/Python/MySQL/setup practice.txt b/erbold/Python/MySQL/setup practice.txt new file mode 100644 index 0000000..045588e --- /dev/null +++ b/erbold/Python/MySQL/setup practice.txt @@ -0,0 +1,5 @@ +USE lead_gen_business; +SELECT * FROM billing; +INSERT INTO billing (amount, charged_datetime, clients_id) VALUES ('A milly', 200, 25); +DELETE FROM billing WHERE id = 1; + diff --git a/erbold/Python/MySQL/twitter.sql/twitter_faves.sql b/erbold/Python/MySQL/twitter.sql/twitter_faves.sql new file mode 100644 index 0000000..2f3e672 --- /dev/null +++ b/erbold/Python/MySQL/twitter.sql/twitter_faves.sql @@ -0,0 +1,60 @@ +CREATE DATABASE IF NOT EXISTS `twitter` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `twitter`; +-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) +-- +-- Host: localhost Database: twitter +-- ------------------------------------------------------ +-- Server version 5.7.20-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `faves` +-- + +DROP TABLE IF EXISTS `faves`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `faves` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `user_id` int(11) NOT NULL, + `tweet_id` int(11) NOT NULL, + `created_at` datetime DEFAULT NULL, + `updated_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_faves_users1_idx` (`user_id`), + KEY `fk_faves_tweets1_idx` (`tweet_id`), + CONSTRAINT `fk_faves_tweets1` FOREIGN KEY (`tweet_id`) REFERENCES `tweets` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT `fk_faves_users1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `faves` +-- + +LOCK TABLES `faves` WRITE; +/*!40000 ALTER TABLE `faves` DISABLE KEYS */; +INSERT INTO `faves` VALUES (1,2,1,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(2,2,2,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(3,3,4,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(4,4,3,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(5,1,9,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(6,1,10,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(7,1,11,'2010-02-01 00:00:01','2010-02-01 00:00:01'); +/*!40000 ALTER TABLE `faves` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-11-20 18:43:10 diff --git a/erbold/Python/MySQL/twitter.sql/twitter_follows.sql b/erbold/Python/MySQL/twitter.sql/twitter_follows.sql new file mode 100644 index 0000000..d07afc8 --- /dev/null +++ b/erbold/Python/MySQL/twitter.sql/twitter_follows.sql @@ -0,0 +1,58 @@ +CREATE DATABASE IF NOT EXISTS `twitter` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `twitter`; +-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) +-- +-- Host: localhost Database: twitter +-- ------------------------------------------------------ +-- Server version 5.7.20-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `follows` +-- + +DROP TABLE IF EXISTS `follows`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `follows` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `followed_id` int(11) NOT NULL, + `follower_id` int(11) DEFAULT NULL, + `created_at` datetime DEFAULT NULL, + `updated_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_follows_users_idx` (`followed_id`), + CONSTRAINT `fk_follows_users` FOREIGN KEY (`followed_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `follows` +-- + +LOCK TABLES `follows` WRITE; +/*!40000 ALTER TABLE `follows` DISABLE KEYS */; +INSERT INTO `follows` VALUES (1,1,2,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(2,1,3,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(3,1,4,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(4,1,5,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(5,3,4,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(6,3,5,'2010-02-01 00:00:01','2010-02-01 00:00:01'),(7,2,4,'2010-02-01 00:00:01','2010-02-01 00:00:01'); +/*!40000 ALTER TABLE `follows` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-11-20 18:43:10 diff --git a/erbold/Python/MySQL/twitter.sql/twitter_tweets.sql b/erbold/Python/MySQL/twitter.sql/twitter_tweets.sql new file mode 100644 index 0000000..7055763 --- /dev/null +++ b/erbold/Python/MySQL/twitter.sql/twitter_tweets.sql @@ -0,0 +1,58 @@ +CREATE DATABASE IF NOT EXISTS `twitter` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `twitter`; +-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) +-- +-- Host: localhost Database: twitter +-- ------------------------------------------------------ +-- Server version 5.7.20-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `tweets` +-- + +DROP TABLE IF EXISTS `tweets`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `tweets` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `tweet` varchar(140) DEFAULT NULL, + `user_id` int(11) NOT NULL, + `created_at` datetime DEFAULT NULL, + `updated_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_tweets_users1_idx` (`user_id`), + CONSTRAINT `fk_tweets_users1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION +) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tweets` +-- + +LOCK TABLES `tweets` WRITE; +/*!40000 ALTER TABLE `tweets` DISABLE KEYS */; +INSERT INTO `tweets` VALUES (1,'There is power in understanding the journey of others to help create your own',1,'2002-02-01 00:00:01','2002-02-01 00:00:01'),(2,'Congrats Coach K! Amazing accomplishment #1KforCoachK #Duke',1,'2005-02-01 00:00:01','2005-02-01 00:00:01'),(3,'This is what happens when I pass too much! #ShoulderShock thank u all for ur thoughts and prayers #team @DrinkBODYARMOR @Lakers #oneluv',1,'2004-02-01 00:00:01','2004-02-01 00:00:01'),(4,'Feeling a mix of emotions I haven\'t felt in 18yrs of being a pro #journey #19th',1,'2012-02-01 00:00:01','2012-02-01 00:00:01'),(5,'Thank you everyone for the birthday wishes. I appreciate you all.',2,'2011-02-01 00:00:01','2011-02-01 00:00:01'),(6,'I\'d like to wish everyone a very Merry Christmas. 1 love to all \"Be Safe\"',2,'2009-02-01 00:00:01','2009-02-01 00:00:01'),(7,'Thanks to all who helped with the Christmas food baskets today. Your time is greatly appreciated. Love & Respect!! ',2,'2008-02-01 00:00:01','2008-02-01 00:00:01'),(8,'I took on the ALS Challenge from Monta Ellis. I challenge @coolkesh42 Jameer Nelson, Dionne Calhoun ... http://tmi.me/1eFAxT ',2,'2003-02-01 00:00:01','2003-02-01 00:00:01'),(9,'Well done lil bro, you deserve it!! @KingJames',3,'2006-02-01 00:00:01','2006-02-01 00:00:01'),(10,'For my basketball clinic with @manilacone 11/4/14, we still have a few slots left for the main game. See you all 11/5/14 Philippines',3,'2001-02-01 00:00:01','2001-02-01 00:00:01'),(11,'Always have a great time with my big little brother. ',4,'2011-02-01 00:00:01','2011-02-01 00:00:01'),(12,'Happy Labor Day..',4,'2014-02-01 00:00:01','2014-02-01 00:00:01'),(13,'hellooo',1,'2017-11-20 12:20:02','2017-11-20 12:20:02'),(14,'i am vino',1,'2017-11-20 12:20:02','2017-11-20 12:20:02'); +/*!40000 ALTER TABLE `tweets` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-11-20 18:43:10 diff --git a/erbold/Python/MySQL/twitter.sql/twitter_users.sql b/erbold/Python/MySQL/twitter.sql/twitter_users.sql new file mode 100644 index 0000000..79ddf58 --- /dev/null +++ b/erbold/Python/MySQL/twitter.sql/twitter_users.sql @@ -0,0 +1,58 @@ +CREATE DATABASE IF NOT EXISTS `twitter` /*!40100 DEFAULT CHARACTER SET utf8 */; +USE `twitter`; +-- MySQL dump 10.13 Distrib 5.7.17, for Win64 (x86_64) +-- +-- Host: localhost Database: twitter +-- ------------------------------------------------------ +-- Server version 5.7.20-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `users` +-- + +DROP TABLE IF EXISTS `users`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + `handle` varchar(255) DEFAULT NULL, + `birthday` date DEFAULT NULL, + `created_at` datetime DEFAULT NULL, + `updated_at` datetime DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `users` +-- + +LOCK TABLES `users` WRITE; +/*!40000 ALTER TABLE `users` DISABLE KEYS */; +INSERT INTO `users` VALUES (1,'Kobe','Bryant','kobebryant','1978-08-23','2010-02-01 00:00:01','2011-07-01 00:00:01'),(2,'Vinky','Carter','mrvincecarter15','1977-01-26','2007-08-11 00:00:01','2010-01-01 00:00:01'),(3,'Allen','Iverson','alleniverson','1975-06-07','2005-09-01 00:00:01','2011-04-21 00:00:01'),(4,'Tracy','McGrady','Real_T_Mac','1979-05-24','2002-12-01 00:00:01','2005-11-21 00:00:01'),(5,'Rajon','Rondo','RajonRondo','1986-02-22','2001-02-01 00:00:01','2002-01-01 00:00:01'); +/*!40000 ALTER TABLE `users` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2017-11-20 18:43:10 diff --git a/erbold/Python/MySQL/walldb/walldb.mwb b/erbold/Python/MySQL/walldb/walldb.mwb new file mode 100644 index 0000000..f83f0bc Binary files /dev/null and b/erbold/Python/MySQL/walldb/walldb.mwb differ diff --git a/erbold/Python/MySQL/workbench1.mwb b/erbold/Python/MySQL/workbench1.mwb new file mode 100644 index 0000000..455449b Binary files /dev/null and b/erbold/Python/MySQL/workbench1.mwb differ diff --git a/erbold/Python/SQL_Flask/Projects/emailVal/mysqlconnection.py b/erbold/Python/SQL_Flask/Projects/emailVal/mysqlconnection.py new file mode 100644 index 0000000..69ecf73 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/emailVal/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/emailVal/server.py b/erbold/Python/SQL_Flask/Projects/emailVal/server.py new file mode 100644 index 0000000..6e3c637 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/emailVal/server.py @@ -0,0 +1,43 @@ +from flask import Flask, request, redirect, render_template, session, flash +from mysqlconnection import MySQLConnector +import re + + +app = Flask(__name__) +mysql = MySQLConnector(app,'emailval') +emailRegex = re.compile(r'^[a-zA-Z0-9\.\+_-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]*$') +app.secret_key = 'yank' + + +@app.route('/') +def index(): + + return render_template('index.html') + +@app.route('/process', methods=['POST']) +def create(): + # add a friend to the database! + session['email'] = request.form['email'] + print session['email'] + if not emailRegex.match(session['email']): + flash("Invalid Email Address!") + return redirect('/') + + else: + flash("Valid Email Address") + query = "INSERT INTO emails (email, created_at, updated_at)VALUES(:email, NOW(), NOW())" + data = { + 'email': request.form['email'] + } + mysql.query_db(query, data) + return redirect('/success') + +@app.route('/success') +def show_emails(): + email = session['email'] + query = "SELECT email, date_format(created_at, '%m:%d:%y %1:%i %p') as created_at FROM emails" + emails = mysql.query_db(query) + + return render_template('success.html', emails = emails, email = email) + +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/emailVal/templates/index.html b/erbold/Python/SQL_Flask/Projects/emailVal/templates/index.html new file mode 100644 index 0000000..8bdc631 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/emailVal/templates/index.html @@ -0,0 +1,22 @@ + + + Email Val. + + + +

Users

+ {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +
+

{{message}}

+
+ {% endfor %} + {% endif %} + {% endwith %} +
+ Email: + +
+ + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/emailVal/templates/success.html b/erbold/Python/SQL_Flask/Projects/emailVal/templates/success.html new file mode 100644 index 0000000..e772adb --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/emailVal/templates/success.html @@ -0,0 +1,23 @@ + + + Total Emails + + + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +
+

{{message}}

+
+ {% endfor %} + {% endif %} + {% endwith %} +

Email Addresses Entered

+ + {% for email in emails %} +

{{email.email}}{{email.created_at}}

+ {% endfor %} + + + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/friends/mysqlconnection.py b/erbold/Python/SQL_Flask/Projects/friends/mysqlconnection.py new file mode 100644 index 0000000..69ecf73 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/friends/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/friends/server.py b/erbold/Python/SQL_Flask/Projects/friends/server.py new file mode 100644 index 0000000..c8d9684 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/friends/server.py @@ -0,0 +1,29 @@ +from flask import Flask, request, redirect, render_template, session, flash +from mysqlconnection import MySQLConnector + +app = Flask(__name__) +mysql = MySQLConnector(app,'friendsdb') + +@app.route('/') +def index(): + query = "SELECT * FROM friends" + friends = mysql.query_db(query) + return render_template('index.html', all_friends=friends) + +@app.route('/friends', methods=['POST']) +def create(): + # add a friend to the database! + print request.form['first_name'] + print request.form['last_name'] + print request.form['occupation'] + query = "INSERT INTO friends (first_name, last_name, occupation, created_at, updated_at) VALUES (:first_name, :last_name, :occupation, NOW(), NOW())" + data = { + 'first_name': request.form['first_name'], + 'last_name': request.form['last_name'], + 'occupation': request.form['occupation'] + } + mysql.query_db(query, data) + + return redirect('/') + +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/friends/templates/index.html b/erbold/Python/SQL_Flask/Projects/friends/templates/index.html new file mode 100644 index 0000000..b86912a --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/friends/templates/index.html @@ -0,0 +1,34 @@ + + + Friends + + + +{{ all_friends }} +

These are all my friends!

+ +{% for friend in all_friends: %} +

ID: {{ friend['id'] }}

+

First Name: {{ friend['first_name'] }}

+

Last Name: {{ friend['last_name'] }}

+

Occupation: {{ friend['occupation'] }}

+
+{% endfor %} + +{% for friend in one_friend: %} +

ID: {{ friend['id'] }}

+

First Name: {{ friend['first_name'] }}

+

Last Name: {{ friend['last_name'] }}

+

Occupation: {{ friend['occupation'] }}

+
+{% endfor %} + +

Add a Friend

+
+ + + + +
+ + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/loginReg/mysqlconnection.py b/erbold/Python/SQL_Flask/Projects/loginReg/mysqlconnection.py new file mode 100644 index 0000000..69ecf73 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/loginReg/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/loginReg/server.py b/erbold/Python/SQL_Flask/Projects/loginReg/server.py new file mode 100644 index 0000000..f214877 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/loginReg/server.py @@ -0,0 +1,110 @@ +from flask import Flask, request, redirect, render_template, session, flash +from mysqlconnection import MySQLConnector +from flask.ext.bcrypt import Bcrypt +import re + + +app = Flask(__name__) +bcrypt = Bcrypt(app) +mysql = MySQLConnector(app,'users') +email_regex = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') +name_regex = re.compile(r'^[A-Z][-a-zA-Z]+$') + +app.secret_key = 'yank' + + +def countLetters(word): + count = 0 + for c in word: + count += 1 + return count + +@app.route('/') +def index(): + + return render_template('index.html') + +@app.route('/process', methods=['POST']) +def create(): + + errors = 0 + session['fname'] = request.form['fname'] + session['lname'] = request.form['lname'] + session['email'] = request.form['email'] + session['password'] = request.form['password'] + session['password2'] = request.form['password2'] + + print session['password'] + + if session['fname'] == '' or session['lname'] == '' or session['email'] == '' or session['password'] == ''or session['password2'] == '': + flash('Submit Error') + errors += 1 + + if not email_regex.match(session['email']): + flash("Invalid Email Address!") + errors += 1 + + if not name_regex.match(session['fname']) or not name_regex.match(session['lname']): + flash('Letters Only Ninja!') + errors += 1 + + if session['password'] != session['password2']: + flash('Password does not match') + errors += 1 + + First_name = countLetters(session['fname']) + print First_name + if First_name < 2: + flash('length error') + errors += 1 + + Last_name = countLetters(session['lname']) + print Last_name + if Last_name < 2: + flash('length error') + errors += 1 + + password = countLetters(session['password']) + print password + if password < 8: + flash('length error') + errors += 1 + + if errors == 0: + flash("Valid Registration") + pw_hash = bcrypt.generate_password_hash(session['password']) + query = "INSERT INTO userinfo (first_name, last_name, email, password, created_at, updated_at)VALUES(:first_name, :last_name, :email, :password, NOW(), NOW())" + data = { + 'first_name': session['fname'], + 'last_name': session['lname'], + 'email': session['email'], + 'password': pw_hash + } + mysql.query_db(query, data) + return redirect('/results') + return redirect('/') + +@app.route('/login', methods=['POST']) +def login(): + + if request.form['email1'] and request.form['password3']: + query = "SELECT * FROM userinfo WHERE email=:email" + data = { + 'email': request.form['email1'] + } + user = mysql.query_db(query, data)[0] + print(user) + if bcrypt.check_password_hash(user['password'], request.form['password3']): + return render_template('/results.html') + flash("Incorrect username or password") + return redirect('/') + +@app.route('/results') +def show_emails(): +# email = session['email'] +# query = "SELECT email, date_format(created_at, '%m:%d:%y %1:%i %p') as created_at FROM emails" +# emails = mysql.query_db(query) + + return render_template('results.html') + +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/loginReg/templates/index.html b/erbold/Python/SQL_Flask/Projects/loginReg/templates/index.html new file mode 100644 index 0000000..1dc4e7b --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/loginReg/templates/index.html @@ -0,0 +1,37 @@ + + + +

Login/Registration

+ {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +
+

{{message}}

+
+ {% endfor %} + {% endif %} + {% endwith %} + + +

Registration

+
+ First name:
+ Last name:
+ Email:
+ Password:
+ Confirm Passw.:
+ +
+ +

Login

+
+ Email:
+ Password:
+ +
+ + + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/loginReg/templates/results.html b/erbold/Python/SQL_Flask/Projects/loginReg/templates/results.html new file mode 100644 index 0000000..fab1ff2 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/loginReg/templates/results.html @@ -0,0 +1,23 @@ + + + Total Emails + + + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +
+

{{message}}

+
+ {% endfor %} + {% endif %} + {% endwith %} +

Good Job

+ + + + + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/loginReg/test.py b/erbold/Python/SQL_Flask/Projects/loginReg/test.py new file mode 100644 index 0000000..cce3161 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/loginReg/test.py @@ -0,0 +1,34 @@ +def validate_login(form_data): + errors = {} + + #email + if len(form_data['email']) == 0: + errors['email'] = "Email is required." + #password + if len(form_data['password']) == 0: + errors['password'] = "Pasword is required." + return errors + + +@app.route('/login', methods = ['POST']) +def login(): + + email = request.form['email'] + password = request.form['password'] + + query = "SELECT * FROM users WHERE users.email = :email LIMIT 1" + data = {'email': email} + user = mysql.query_db(query, data) + + if len(user) != 0: + encrypted_password = md5.new(password + user[0]['salt']).hexdigest() + if user[0]['hashed_pw'] == encrypted_password: + return redirect('/success') + else: + flash('invalid login homie!') + return redirect('/') + else: + flash('invalid login homie!') + return redirect('/') + +app.run(debug=True) diff --git a/erbold/Python/SQL_Flask/Projects/wall/mysqlconnection.py b/erbold/Python/SQL_Flask/Projects/wall/mysqlconnection.py new file mode 100644 index 0000000..69ecf73 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/wall/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/wall/server.py b/erbold/Python/SQL_Flask/Projects/wall/server.py new file mode 100644 index 0000000..d0939f0 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/wall/server.py @@ -0,0 +1,159 @@ +from flask import Flask, request, redirect, render_template, session, flash +from mysqlconnection import MySQLConnector +from flask.ext.bcrypt import Bcrypt +import re + + +app = Flask(__name__) +bcrypt = Bcrypt(app) +mysql = MySQLConnector(app,'users') +email_regex = re.compile(r'^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$') +name_regex = re.compile(r'^[A-Z][-a-zA-Z]+$') + +app.secret_key = 'yank' + + +def countLetters(word): + count = 0 + for c in word: + count += 1 + return count + +@app.route('/') +def index(): + + return render_template('index.html') + +@app.route('/process', methods=['POST']) +def create(): + + errors = 0 + session['fname'] = request.form['fname'] + session['lname'] = request.form['lname'] + session['email'] = request.form['email'] + session['password'] = request.form['password'] + session['password2'] = request.form['password2'] + + print session['password'] + + if session['fname'] == '' or session['lname'] == '' or session['email'] == '' or session['password'] == ''or session['password2'] == '': + flash('Submit Error') + errors += 1 + + if not email_regex.match(session['email']): + flash("Invalid Email Address!") + errors += 1 + + if not name_regex.match(session['fname']) or not name_regex.match(session['lname']): + flash('Letters Only Ninja!') + errors += 1 + + if session['password'] != session['password2']: + flash('Password does not match') + errors += 1 + + First_name = countLetters(session['fname']) + print First_name + if First_name < 2: + flash('length error') + errors += 1 + + Last_name = countLetters(session['lname']) + print Last_name + if Last_name < 2: + flash('length error') + errors += 1 + + password = countLetters(session['password']) + print password + if password < 8: + flash('length error') + errors += 1 + + if errors == 0: + flash("Valid Registration") + pw_hash = bcrypt.generate_password_hash(session['password']) + query = "INSERT INTO userinfo (first_name, last_name, email, password, created_at, updated_at)VALUES(:first_name, :last_name, :email, :password, NOW(), NOW())" + data = { + 'first_name': session['fname'], + 'last_name': session['lname'], + 'email': session['email'], + 'password': pw_hash + } + user = mysql.query_db(query, data) + session['userid'] = user[0]['id'] + return redirect('/results') + return redirect('/') + +@app.route('/login', methods=['POST']) +def login(): + + if request.form['email1'] and request.form['password3']: + query = "SELECT * FROM userinfo WHERE email=:email" + data = { + 'email': request.form['email1'] + } + user = mysql.query_db(query, data)[0] + print(user) + if bcrypt.check_password_hash(user['password'], request.form['password3']): + session['userid'] = user[0]['id'] + return redirect('/wall') + flash("Incorrect username or password") + return redirect('/') + +@app.route('/logout', methods=['POST']) +def logout(): + + session.clear() + return redirect('/') + + +@app.route('/wall') +def wall(): + + if session.get('userid') == 0: + return redirect('/') + + userquery = "SELECT first_name, last_name FROM users WHERE users.id = :id" + userdata = {'id': session['userid']} + user = mysql.query_db(userquery, userdata) + + messagequery = "SELECT users.id, messages.id, first_name, last_name, message, messages.created_at FROM users JOIN messages ON users.id = messages.users_id ORDER BY messages.created_at DESC" + messages = mysql.query_db(messagequery) + + commentquery = "SELECT messages.id AS message_id, comments.id AS comment_id, first_name, last_name, comment, comments.created_at FROM comments JOIN messages ON comments.messages_id = messages.id JOIN users ON comments.users_id = users.id ORDER BY comments.created_at DESC" + comments = mysql.query_db(commentquery) + + return render_template('wall.html', + first_name = user[0]['first_name'], + all_messages = messages, + all_comments = comments) + + +@app.route('/message', methods=['POST']) +def message(): + + message = request.form['message'] + query = "INSERT INTO messages (users_id, message, created_at, updated_at) VALUES (:users_id, :message, NOW(), NOW())" + data = { + 'users_id': session['userid'], + 'message': message + } + mysql.query_db(query, data) + return redirect('/wall') + +@app.route('/comment', methods=['POST']) +def comment(): + comment = request.form['comment'] + message_id = request.form['message_id'] + query = "INSERT INTO comments (users_id, messages_id, comment, created_at, updated_at) VALUES (:users_id, :messages_id, :comment, NOW(), NOW())" + data = { + 'users_id': session['userid'], + 'messages_id': message_id, + 'comment': comment + } + mysql.query_db(query, data) + return redirect('/wall') + + +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/wall/static/css/style.css b/erbold/Python/SQL_Flask/Projects/wall/static/css/style.css new file mode 100644 index 0000000..fcbd0f6 --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/wall/static/css/style.css @@ -0,0 +1,17 @@ +.message { + display: inline-block; + border: solid 2px black; + text-align: right; + margin-bottom: 30px; + margin-left: 10px; + padding: 10px; +} + +h2 { + margin-top: 100px; +} + +textarea { + width: 500px; + height: 50px; +} \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/wall/templates/index.html b/erbold/Python/SQL_Flask/Projects/wall/templates/index.html new file mode 100644 index 0000000..4e44eed --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/wall/templates/index.html @@ -0,0 +1,31 @@ + + + Wall - Login and Registration page + + + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} +

{{ message }}

+ {% endfor %} + {% endif %} + {% endwith %} + +

Login

+
+
+
+ +
+ +

Registration

+
+
+
+
+
+
+ +
+ + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/wall/templates/success.html b/erbold/Python/SQL_Flask/Projects/wall/templates/success.html new file mode 100644 index 0000000..ad16deb --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/wall/templates/success.html @@ -0,0 +1,44 @@ + + + Wall - Wall + + + +

Wall - Welcome {{ first_name }}

+ Logout + +

Post a message

+
+
+ +
+ + + {% if all_messages != Null %} + {% for message in all_messages: %} +

{{ message['id'] }} - {{ message['first_name'] }} {{ message['last_name'] }} - {{ message['created_at'] }}

+

{{ message['message'] }}

+ + + {% if all_comments != Null %} + {% for comment in all_comments: %} + {% if comment['message_id'] == message['id'] %} +

+ {{ comment['first_name'] }} {{ comment['last_name'] }} - {{ comment['created_at'] }} +

+

{{ comment['comment'] }}

+ {% endif %} + {% endfor %} + {% endif %} + +

Post a comment

+
+ +
+ +
+ {% endfor %} + {% endif %} + + + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/Projects/wall/templates/wall.html b/erbold/Python/SQL_Flask/Projects/wall/templates/wall.html new file mode 100644 index 0000000..ad16deb --- /dev/null +++ b/erbold/Python/SQL_Flask/Projects/wall/templates/wall.html @@ -0,0 +1,44 @@ + + + Wall - Wall + + + +

Wall - Welcome {{ first_name }}

+ Logout + +

Post a message

+
+
+ +
+ + + {% if all_messages != Null %} + {% for message in all_messages: %} +

{{ message['id'] }} - {{ message['first_name'] }} {{ message['last_name'] }} - {{ message['created_at'] }}

+

{{ message['message'] }}

+ + + {% if all_comments != Null %} + {% for comment in all_comments: %} + {% if comment['message_id'] == message['id'] %} +

+ {{ comment['first_name'] }} {{ comment['last_name'] }} - {{ comment['created_at'] }} +

+

{{ comment['comment'] }}

+ {% endif %} + {% endfor %} + {% endif %} + +

Post a comment

+
+ +
+ +
+ {% endfor %} + {% endif %} + + + \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/friends.sql b/erbold/Python/SQL_Flask/friends.sql new file mode 100644 index 0000000..500bc1f --- /dev/null +++ b/erbold/Python/SQL_Flask/friends.sql @@ -0,0 +1,23 @@ +1) +$ python server.py +Traceback (most recent call last): + File "server.py", line 2, in + from mysqlconnection import MySQLConnector + File "C:\Users\Erbold Uran\Documents\Coding Dojo\python_nov_2017\erbold\Python\SQL_Flask\Projects\friends\mysqlconnection.py", line 2, in + from flask_sqlalchemy import SQchemy +ImportError: cannot import name SQchemy +(flaskEnv) + + +fix - Typed SQLAlchemy correctly + +2) +OperationalError: (_mysql_exceptions.OperationalError) (1049, "Unknown database 'db'") + +fix - Converted db back into a value after making it a string + +3) +NameError: global name 'result' is not defined + +fix - I had to set it equal to the original variable name so that i could link it with +the rest of the program diff --git a/erbold/Python/SQL_Flask/mysqlconnection.py b/erbold/Python/SQL_Flask/mysqlconnection.py new file mode 100644 index 0000000..69ecf73 --- /dev/null +++ b/erbold/Python/SQL_Flask/mysqlconnection.py @@ -0,0 +1,40 @@ +""" import the necessary modules """ +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text +# Create a class that will give us an object that we can use to connect to a database +class MySQLConnection(object): + def __init__(self, app, db): + config = { + 'host': 'localhost', + 'database': db, # we got db as an argument + 'user': 'root', + 'password': 'root', + 'port': '3306' # change the port to match the port your SQL server is running on + } + # this will use the above values to generate the path to connect to your sql database + DATABASE_URI = "mysql://{}:{}@127.0.0.1:{}/{}".format(config['user'], config['password'], config['port'], config['database']) + app.config['SQLALCHEMY_DATABASE_URI'] = DATABASE_URI + app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True + # establish the connection to database + self.db = SQLAlchemy(app) + # this is the method we will use to query the database + def query_db(self, query, data=None): + result = self.db.session.execute(text(query), data) + if query[0:6].lower() == 'select': + # if the query was a select + # convert the result to a list of dictionaries + list_result = [dict(r) for r in result] + # return the results as a list of dictionaries + return list_result + elif query[0:6].lower() == 'insert': + # if the query was an insert, return the id of the + # commit changes + self.db.session.commit() + # row that was inserted + return result.lastrowid + else: + # if the query was an update or delete, return nothing and commit changes + self.db.session.commit() +# This is the module method to be called by the user in server.py. Make sure to provide the db name! +def MySQLConnector(app, db): + return MySQLConnection(app, db) \ No newline at end of file diff --git a/erbold/Python/SQL_Flask/server.py b/erbold/Python/SQL_Flask/server.py new file mode 100644 index 0000000..cefb214 --- /dev/null +++ b/erbold/Python/SQL_Flask/server.py @@ -0,0 +1,9 @@ +from flask import Flask +# import the Connector function +from mysqlconnection import MySQLConnector +app = Flask(__name__) +# connect and store the connection in "mysql"; note that you pass the database name to the function +mysql = MySQLConnector(app, 'mydb') +# an example of running a query +print mysql.query_db("SELECT * FROM users") +app.run(debug=True) \ No newline at end of file diff --git a/erbold/Python/workbench1.mwb b/erbold/Python/workbench1.mwb.bak similarity index 100% rename from erbold/Python/workbench1.mwb rename to erbold/Python/workbench1.mwb.bak