Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
40 changes: 40 additions & 0 deletions ian_you/Flask_MySQL/assignment_emailValidation/mysqlconnection.py
Original file line number Diff line number Diff line change
@@ -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)
50 changes: 50 additions & 0 deletions ian_you/Flask_MySQL/assignment_emailValidation/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from flask import Flask, render_template, request, redirect
# 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, 'assignment_emailvalidation')
# an example of running a query

@app.route('/')
def index():
return render_template('index.html')

@app.route('/', methods=['POST'])
def verify():
username = request.form['email'].split('@')[0]

domainLength = len(request.form['email'].split('@')[1].split('.'))

i=0
domain=""

for i in range (0, domainLength-1):
domain += request.form['email'].split('@')[1].split('.')[i]+"."

extension = request.form['email'].split('@')[1].split('.')[domainLength-1]

if username == "" or domain == "" or extension == "":
error = "Email is not a valid email address"

return render_template('index.html', error=error)

query = "INSERT INTO emails (username, domain, extension, created_at, updated_at) VALUES (:username, :domain, :extension, NOW(), NOW())"

data = {
'username':username,
'domain': domain,
'extension':extension
}

mysql.query_db(query, data)
return redirect ('/success')

@app.route('/success')
def success():
query = "SELECT username, domain, extension, created_at FROM emails;"
emails = mysql.query_db(query)

return render_template('success.html', emails=emails)

app.run(debug=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
h1{
color: red;
}

#Valid{
color: black;
background-color: green;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Assignment Email Validation</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">

</head>
<body>
<h1>{{error}}</h1>
<form action="/" method="post">
<p>Email Address: <input type="email" name="email" /></p>
<p><input type="submit" value="Submit"> </p>
</form>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Assignment Email Validation</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">

</head>
<body>
<div id="Valid">
The email address you entered "" is a VALID email address! Thank you!

</div>
<h2>Email Address Entered</h2>
<table>
{% for email in emails %}
<tr>
<td>{{email['username']+'@'+email['domain']+email['extension']}}</td>
<td>{{email['created_at']}}</td>
</tr>
{% endfor%}
</table>
</body>
</html>
Binary file added ian_you/Flask_MySQL/assignment_friends/ERD.mwb
Binary file not shown.
Binary file not shown.
40 changes: 40 additions & 0 deletions ian_you/Flask_MySQL/assignment_friends/mysqlconnection.py
Original file line number Diff line number Diff line change
@@ -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)
27 changes: 27 additions & 0 deletions ian_you/Flask_MySQL/assignment_friends/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from flask import Flask, render_template, request, redirect
# 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, 'assignment_friends')
# an example of running a query

@app.route('/')
def index():
query = "SELECT * FROM friends;"
friends = mysql.query_db(query)
return render_template('index.html', friends=friends)


@app.route('/add', methods = ['POST'])
def add():
query = "INSERT INTO friends (name, age, created_at, updated_at) VALUES (:name, :age, NOW(), NOW());"

data = {
'name':request.form['name'],
'age':request.form['age'],
}
mysql.query_db(query, data)
return redirect ('/')

app.run(debug=True)
42 changes: 42 additions & 0 deletions ian_you/Flask_MySQL/assignment_friends/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Assignment Friends</title>
</head>
<body>
<div>
<h1>Add a Friend</h1>
<form action="/add" method="POST">
<label for="name">Name</label>
<input type="text" name="name" />
<label for="age">Age</label>
<input type="text" name="age" />
<input type="submit" value="Add" />
</form>
</div>
<div>
<h1>Friends List</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Added Since</th>
</tr>
</thead>
<tbody>
{% for friend in friends %}
<tr>
<td>{{friend['name']}}</td>
<td>{{friend['age']}}</td>
<td>{{friend['created_at']}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
21 changes: 21 additions & 0 deletions ian_you/Python_Flask/Disappearing_Ninja/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from flask import Flask, render_template, redirect

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/ninja')
def allninja():
return render_template('allNinjas.html')

@app.route('/ninja/<color>')
def colorninja(color):
if color == "blue" or color == "red" or color == "orange" or color == "purple":
return render_template('ninja.html', color=color)
else:
color="notapril"
return render_template('ninja.html', color=color)

app.run(debug=True)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions ian_you/Python_Flask/Disappearing_Ninja/templates/allNinjas.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>All Ninjas</title>
</head>
<body>
<h1>All Ninjas</h1>
<img src="{{ url_for('static', filename='img/tmnt.png') }}" alt="All Ninjas">
</body>
</html>
12 changes: 12 additions & 0 deletions ian_you/Python_Flask/Disappearing_Ninja/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>No Ninja</title>
</head>
<body>
<h1>No Ninjas Here~</h1>
</body>
</html>
13 changes: 13 additions & 0 deletions ian_you/Python_Flask/Disappearing_Ninja/templates/ninja.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ninja</title>
</head>
<body>
<h1>Ninja</h1>
<img src="{{url_for('static', filename='img/'+color+'.jpg') }}" alt="Blue Ninja">
</body>
</html>
36 changes: 36 additions & 0 deletions ian_you/Python_Flask/FunwithFunctions/assignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Odd /Even

def oddEven():
for i in range (1,2001):
if i%2==0:
print "Number is "+str(i)+". This is an even number."
else:
print "Number is "+str(i)+". This is an odd number."

oddEven()

# Multiply
def multiply(a, c):
new=[]
for i in range (0, len(a)):
new.append(a[i]*c)
return new

a = [2,4,10,16]
b = multiply(a, 5)
print b



# Hacker Challenge (!!!Not Finished!!!)
def hackerChanllenge(arr):
new_array=[]
for j in range (len(arr)):
small_list = []
for k in range (arr[j]):
small_list.append(1)
new_array.append(small_list)
return new_array

x= hackerChanllenge(multiply([2,4,5],3))
print x
10 changes: 10 additions & 0 deletions ian_you/Python_Flask/Hello World/helloworld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask import Flask, render_template

app = Flask(__name__)

@app.route('/')

def hello_world():
return render_template('index.html')

app.run(debug=True)
13 changes: 13 additions & 0 deletions ian_you/Python_Flask/Hello World/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
<p>My name is Ian</p>
</body>
</html>
13 changes: 13 additions & 0 deletions ian_you/Python_Flask/Landing Page/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from flask import Flask, render_template

app= Flask(__name__)
@app.route('/')
def index():
return render_template("index.html", word="Home Page")
@app.route('/ninjas')
def ninjas():
return render_template("ninjas.html", word="Ninjas")
@app.route('/dojos/new')
def dojo():
return render_template("dojos.html", word="Ninjas")
app.run(debug=True)
Loading