Skip to content

Commit f9a737e

Browse files
author
DSA Data Ops
committed
Update Curso Version 3
1 parent 5833666 commit f9a737e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1239
-1
lines changed

Cap13/01-PrimeirosPassos/hello.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import Flask
2+
app = Flask(__name__)
3+
4+
@app.route("/")
5+
def hello():
6+
return "Hello World!"
7+
8+
if __name__ == "__main__":
9+
app.run()
10+
11+

Cap13/01-PrimeirosPassos/hello2.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import Flask
2+
app = Flask(__name__)
3+
4+
@app.route("/")
5+
def index():
6+
return "Index!"
7+
8+
@app.route("/hello")
9+
def hello():
10+
return "Hello World!"
11+
12+
@app.route("/members")
13+
def members():
14+
return "Members"
15+
16+
@app.route("/members/<string:name>/")
17+
def getMember(name):
18+
return name
19+
20+
if __name__ == "__main__":
21+
app.run()
22+
23+

Cap13/01-PrimeirosPassos/hello3.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from flask import Flask, flash, redirect, render_template, request, session, abort
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/")
6+
def index():
7+
return "Flask App!"
8+
9+
@app.route("/hello/<string:name>/")
10+
def hello(name):
11+
return render_template('template1.html',name=name)
12+
13+
if __name__ == "__main__":
14+
app.run(host='0.0.0.0', port=80)
15+
16+

Cap13/01-PrimeirosPassos/hello4.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from flask import Flask, flash, redirect, render_template, request, session, abort
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/")
6+
def index():
7+
return "Flask App!"
8+
9+
@app.route("/hello/<string:name>/")
10+
def hello(name):
11+
return render_template('template2.html',name=name)
12+
13+
if __name__ == "__main__":
14+
app.run(host='0.0.0.0', port=80)
15+
16+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<html>
2+
<head>
3+
<title>Website</title>
4+
<style>
5+
@import url(http://fonts.googleapis.com/css?family=Amatic+SC:700);
6+
7+
body{
8+
text-align: center;
9+
}
10+
h1{
11+
font-family: 'Amatic SC', cursive;
12+
font-weight: normal;
13+
color: #8ac640;
14+
font-size: 2.5em;
15+
}
16+
17+
</style>
18+
19+
</head>
20+
<body>
21+
{% block body %}{% endblock %}
22+
23+
</body>
24+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello {{name}}</h1>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "layout.html" %}
2+
{% block body %}
3+
4+
<div class="block1">
5+
<h1>Hello {{name}}!</h1>
6+
<h2>Pronto para aprender algo novo hoje? Um dia sem aprender algo novo é um dia perdido!</h2>
7+
<p>"O único limite que existe é aquele que você impõe a si mesmo."</p>
8+
<img src="https://images.freeimages.com/images/large-previews/007/books-1419617.jpg">
9+
</div>
10+
{% endblock %}

Cap13/02-WebApp/Leiame.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Para executar a app, digite:
2+
3+
python app.py

Cap13/02-WebApp/app.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from flask import Flask, render_template, json, request
2+
from werkzeug import generate_password_hash, check_password_hash
3+
# pip install flask-mysql (Mac/Linux)
4+
# pip install Flask-MySQL (Windows)
5+
from flaskext.mysql import MySQL
6+
7+
8+
mysql = MySQL()
9+
app = Flask(__name__)
10+
11+
# MySQL setup
12+
app.config['MYSQL_DATABASE_USER'] = 'appuser'
13+
app.config['MYSQL_DATABASE_PASSWORD'] = 'app9872#'
14+
app.config['MYSQL_DATABASE_DB'] = 'appdb'
15+
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
16+
mysql.init_app(app)
17+
18+
19+
@app.route('/')
20+
def main():
21+
return render_template('index.html')
22+
23+
@app.route('/showSignUp')
24+
def showSignUp():
25+
return render_template('signup.html')
26+
27+
28+
@app.route('/signUp',methods=['POST','GET'])
29+
def signUp():
30+
try:
31+
_name = request.form['inputName']
32+
_email = request.form['inputEmail']
33+
_password = request.form['inputPassword']
34+
35+
# Valida os dados recebidos
36+
if _name and _email and _password:
37+
38+
with closing(mysql.connect()) as conn:
39+
with closing(conn.cursor()) as cursor:
40+
41+
_hashed_password = generate_password_hash(_password)
42+
cursor.callproc('sp_createUser',(_name,_email,_hashed_password))
43+
data = cursor.fetchall()
44+
45+
if len(data) is 0:
46+
conn.commit()
47+
return json.dumps({'message':'User criado com sucesso!'})
48+
else:
49+
return json.dumps({'error':str(data[0])})
50+
else:
51+
return json.dumps({'html':'<span>preencha os campos requeridos</span>'})
52+
53+
except Exception as e:
54+
return json.dumps({'error':str(e)})
55+
56+
if __name__ == "__main__":
57+
app.run(port=5002)

Cap13/02-WebApp/sql/create_table.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE TABLE `appdb`.`tbl_user` (
2+
`user_id` INT NOT NULL AUTO_INCREMENT,
3+
`user_name` VARCHAR(45) NULL,
4+
`user_email` VARCHAR(45) NULL,
5+
`user_password` VARCHAR(45) NULL,
6+
PRIMARY KEY (`user_id`));
7+
8+
grant insert on tbl_user to appuser;

Cap13/02-WebApp/sql/sp_createUser.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE DEFINER=`appuser`@`localhost` PROCEDURE `sp_createUser`(
2+
IN p_name VARCHAR(45),
3+
IN p_email VARCHAR(45),
4+
IN p_password VARCHAR(45)
5+
)
6+
BEGIN
7+
if ( select exists (select 1 from tbl_user where user_email = p_email) ) THEN
8+
9+
select 'User Existe !!';
10+
11+
ELSE
12+
13+
insert into tbl_user
14+
(
15+
user_name,
16+
user_email,
17+
user_password
18+
)
19+
values
20+
(
21+
p_name,
22+
p_email,
23+
p_password
24+
);
25+
26+
END IF;
27+
END$$

Cap13/02-WebApp/static/css/signup.css

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
body {
2+
padding-top: 40px;
3+
padding-bottom: 40px;
4+
}
5+
6+
.form-signin {
7+
max-width: 330px;
8+
padding: 15px;
9+
margin: 0 auto;
10+
}
11+
.form-signin .form-signin-heading,
12+
.form-signin .checkbox {
13+
margin-bottom: 10px;
14+
}
15+
.form-signin .checkbox {
16+
font-weight: normal;
17+
}
18+
.form-signin .form-control {
19+
position: relative;
20+
height: auto;
21+
-webkit-box-sizing: border-box;
22+
-moz-box-sizing: border-box;
23+
box-sizing: border-box;
24+
padding: 10px;
25+
font-size: 16px;
26+
}
27+
.form-signin .form-control:focus {
28+
z-index: 2;
29+
}
30+
.form-signin input[type="email"] {
31+
margin-bottom: -1px;
32+
border-bottom-right-radius: 0;
33+
border-bottom-left-radius: 0;
34+
}
35+
.form-signin input[type="password"] {
36+
margin-bottom: 10px;
37+
border-top-left-radius: 0;
38+
border-top-right-radius: 0;
39+
}

Cap13/02-WebApp/static/js/jquery-3.3.1.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cap13/02-WebApp/static/js/signUp.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$(function(){
2+
$('#btnSignUp').click(function(){
3+
4+
$.ajax({
5+
url: '/signUp',
6+
data: $('form').serialize(),
7+
type: 'POST',
8+
success: function(response){
9+
console.log(response);
10+
},
11+
error: function(error){
12+
console.log(error);
13+
}
14+
});
15+
});
16+
});

Cap13/02-WebApp/templates/index.html

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<title>Python Flask App</title>
6+
7+
8+
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
9+
10+
<link href="https://getbootstrap.com/docs/3.3/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
11+
12+
13+
</head>
14+
15+
<body>
16+
17+
<div class="container">
18+
<div class="header">
19+
<nav>
20+
<ul class="nav nav-pills pull-right">
21+
<li role="presentation"><a href="#">Login</a></li>
22+
</ul>
23+
</nav>
24+
<h3 class="text-muted">Portfólio do Cientista de Dados</h3>
25+
</div>
26+
27+
<div class="jumbotron">
28+
<h1>Acompanhe Meu Portfólio de Projetos</h1>
29+
<p class="lead"></p>
30+
<p><a class="btn btn-lg btn-success" href="showSignUp" role="button">Faça Seu Cadastro</a></p>
31+
</div>
32+
33+
<div class="row marketing">
34+
<div class="col-lg-6">
35+
<h4>Projeto 1</h4>
36+
<p>Criação de App Analítica Para Previsão de Vendas.</p>
37+
38+
<h4>Projeto 2</h4>
39+
<p>Análise de Sentimentos em Tempo Real.</p>
40+
41+
<h4>Projeto 3</h4>
42+
<p>Detecção de Fraude na Contabilidade.</p>
43+
</div>
44+
45+
<div class="col-lg-6">
46+
<h4>Projeto 4</h4>
47+
<p>Análise e Previsão de Turnover dos Colaboradores.</p>
48+
49+
<h4>Projeto 5</h4>
50+
<p>Dashboard de Previsão de Faturamento em Tempo Real Por Produto e Por Região.</p>
51+
52+
<h4>Projeto 6</h4>
53+
<p>Robô Advogado.</p>
54+
</div>
55+
</div>
56+
57+
<footer class="footer">
58+
<p>&copy; Data Science Academy</p>
59+
</footer>
60+
61+
</div>
62+
</body>
63+
</html>
64+

Cap13/02-WebApp/templates/signup.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
<!DOCTYPE html>
3+
<html lang="en">
4+
<head>
5+
<title>Python Flask App</title>
6+
7+
8+
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet">
9+
10+
<link href="https://getbootstrap.com/docs/3.3/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
11+
<link href="../static/css/signup.css" rel="stylesheet">
12+
<script src="../static/js/jquery-3.3.1.min.js"></script>
13+
<script src="../static/js/signUp.js"></script>
14+
15+
</head>
16+
17+
<body>
18+
19+
<div class="container">
20+
<div class="header">
21+
<nav>
22+
<ul class="nav nav-pills pull-right">
23+
<li role="presentation"><a href="#">Login</a></li>
24+
</ul>
25+
</nav>
26+
<h3 class="text-muted">Portfólio do Cientista de Dados</h3>
27+
</div>
28+
29+
<div class="jumbotron">
30+
<h1>Acompanhe Meu Portfólio de Projetos</h1>
31+
<form class="form-signin">
32+
<label for="inputName" class="sr-only">Nome</label>
33+
<input type="name" name="inputName" id="inputName" class="form-control" placeholder="Name" required autofocus>
34+
<label for="inputEmail" class="sr-only">Email</label>
35+
<input type="email" name="inputEmail" id="inputEmail" class="form-control" placeholder="Email" required autofocus>
36+
<label for="inputPassword" class="sr-only">Password</label>
37+
<input type="password" name="inputPassword" id="inputPassword" class="form-control" placeholder="Password" required>
38+
39+
<button id="btnSignUp" class="btn btn-lg btn-primary btn-block" type="button">Cadastrar</button>
40+
</form>
41+
</div>
42+
43+
44+
45+
<footer class="footer">
46+
<p>&copy; Data Science Academy</p>
47+
</footer>
48+
49+
</div>
50+
</body>
51+
</html>
52+

0 commit comments

Comments
 (0)