├── aula2 ├── .dockerignore ├── .gitignore ├── install.sh ├── run.py ├── .pre-commit-config.yaml ├── Dockerfile └── requirements.txt ├── aula1 ├── .gitignore ├── install.sh ├── run.py ├── .pre-commit-config.yaml └── requirements.txt ├── aula4 ├── src │ ├── entities │ │ ├── __init__.py │ │ └── users.py │ ├── config │ │ ├── __init__.py │ │ ├── base.py │ │ └── config.py │ └── __init__.py ├── install.sh ├── init │ └── schema.sql ├── Dockerfile ├── requirements.txt └── run.py ├── aula5 ├── src │ ├── entities │ │ ├── __init__.py │ │ └── users.py │ ├── config │ │ ├── __init__.py │ │ ├── base.py │ │ └── config.py │ └── __init__.py ├── install.sh ├── init │ └── schema.sql ├── Dockerfile ├── run.py ├── requirements.txt └── docker-compose.yml └── aula3 ├── install.sh ├── run.py ├── init └── schema.sql ├── Dockerfile └── requirements.txt /aula2/.dockerignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | venv -------------------------------------------------------------------------------- /aula1/.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | venv 3 | -------------------------------------------------------------------------------- /aula2/.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | venv 3 | -------------------------------------------------------------------------------- /aula4/src/entities/__init__.py: -------------------------------------------------------------------------------- 1 | from .users import Users -------------------------------------------------------------------------------- /aula5/src/entities/__init__.py: -------------------------------------------------------------------------------- 1 | from .users import Users -------------------------------------------------------------------------------- /aula4/src/config/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import Base 2 | from .config import DBConnection -------------------------------------------------------------------------------- /aula5/src/config/__init__.py: -------------------------------------------------------------------------------- 1 | from .base import Base 2 | from .config import DBConnection -------------------------------------------------------------------------------- /aula4/src/config/base.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy.ext.declarative import declarative_base 2 | Base = declarative_base() 3 | -------------------------------------------------------------------------------- /aula5/src/config/base.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy.ext.declarative import declarative_base 2 | Base = declarative_base() 3 | -------------------------------------------------------------------------------- /aula1/install.sh: -------------------------------------------------------------------------------- 1 | virtualenv -p python3 venv; 2 | . venv/bin/activate; 3 | pip3 install -r requirements.txt; 4 | pre-commit install; 5 | -------------------------------------------------------------------------------- /aula2/install.sh: -------------------------------------------------------------------------------- 1 | virtualenv -p python3 venv; 2 | . venv/bin/activate; 3 | pip3 install -r requirements.txt; 4 | pre-commit install; 5 | -------------------------------------------------------------------------------- /aula3/install.sh: -------------------------------------------------------------------------------- 1 | virtualenv -p python3 venv; 2 | . venv/bin/activate; 3 | pip3 install -r requirements.txt; 4 | pre-commit install; 5 | -------------------------------------------------------------------------------- /aula4/install.sh: -------------------------------------------------------------------------------- 1 | virtualenv -p python3 venv; 2 | . venv/bin/activate; 3 | pip3 install -r requirements.txt; 4 | pre-commit install; 5 | -------------------------------------------------------------------------------- /aula5/install.sh: -------------------------------------------------------------------------------- 1 | virtualenv -p python3 venv; 2 | . venv/bin/activate; 3 | pip3 install -r requirements.txt; 4 | pre-commit install; 5 | -------------------------------------------------------------------------------- /aula1/run.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | @app.route("/", methods=["GET"]) 5 | def hello_world(): 6 | return 'Ola, estou na aplicação setada' 7 | -------------------------------------------------------------------------------- /aula2/run.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | @app.route("/", methods=["GET"]) 5 | def hello_world(): 6 | return 'Ola, estou na aplicação setada' 7 | -------------------------------------------------------------------------------- /aula3/run.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | app = Flask(__name__) 3 | 4 | @app.route("/", methods=["GET"]) 5 | def hello_world(): 6 | return 'Ola, estou na aplicação setada' 7 | -------------------------------------------------------------------------------- /aula5/init/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE teste; 2 | 3 | CREATE TABLE IF NOT EXISTS `teste`.`users` ( 4 | id INT AUTO_INCREMENT PRIMARY KEY, 5 | name VARCHAR(255) NOT NULL 6 | ) ENGINE=INNODB; 7 | -------------------------------------------------------------------------------- /aula3/init/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE teste; 2 | 3 | CREATE TABLE IF NOT EXISTS `teste`.`users` ( 4 | id INT AUTO_INCREMENT PRIMARY KEY, 5 | name VARCHAR(255) NOT NULL 6 | ) ENGINE=INNODB; 7 | 8 | -------------------------------------------------------------------------------- /aula4/init/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE DATABASE teste; 2 | 3 | CREATE TABLE IF NOT EXISTS `teste`.`users` ( 4 | id INT AUTO_INCREMENT PRIMARY KEY, 5 | name VARCHAR(255) NOT NULL 6 | ) ENGINE=INNODB; 7 | 8 | -------------------------------------------------------------------------------- /aula1/.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: local 3 | hooks: 4 | - id: requirements 5 | name: requirements 6 | entry: bash -c 'venv/bin/pip3 freeze > requirements.txt; git add requirements.txt' 7 | language: system 8 | pass_filenames: false 9 | stages: [commit] -------------------------------------------------------------------------------- /aula2/.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: local 3 | hooks: 4 | - id: requirements 5 | name: requirements 6 | entry: bash -c 'venv/bin/pip3 freeze > requirements.txt; git add requirements.txt' 7 | language: system 8 | pass_filenames: false 9 | stages: [commit] -------------------------------------------------------------------------------- /aula2/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM python:3.8-slim-buster 4 | 5 | WORKDIR /app 6 | ENV FLASK_APP run.py 7 | 8 | COPY requirements.txt requirements.txt 9 | RUN pip3 install -r requirements.txt 10 | 11 | COPY . . 12 | 13 | CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] 14 | -------------------------------------------------------------------------------- /aula3/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM python:3.8-slim-buster 4 | 5 | WORKDIR /app 6 | ENV FLASK_APP run.py 7 | 8 | COPY requirements.txt requirements.txt 9 | RUN pip3 install -r requirements.txt 10 | 11 | COPY . . 12 | 13 | CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] 14 | -------------------------------------------------------------------------------- /aula4/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM python:3.8-slim-buster 4 | 5 | WORKDIR /app 6 | ENV FLASK_APP run.py 7 | 8 | COPY requirements.txt requirements.txt 9 | RUN pip3 install -r requirements.txt 10 | 11 | COPY . . 12 | 13 | CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] 14 | -------------------------------------------------------------------------------- /aula5/Dockerfile: -------------------------------------------------------------------------------- 1 | # syntax=docker/dockerfile:1 2 | 3 | FROM python:3.8-slim-buster 4 | 5 | WORKDIR /app 6 | ENV FLASK_APP run.py 7 | 8 | COPY requirements.txt requirements.txt 9 | RUN pip3 install -r requirements.txt 10 | 11 | COPY . . 12 | 13 | CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] 14 | -------------------------------------------------------------------------------- /aula4/src/__init__.py: -------------------------------------------------------------------------------- 1 | from .config import DBConnection 2 | from .entities import Users as UsersModel 3 | 4 | class UserRepo: 5 | 6 | def insert_user(self, name): 7 | with DBConnection() as db: 8 | new_user = UsersModel(name=name) 9 | db.session.add(new_user) 10 | db.session.commit() 11 | -------------------------------------------------------------------------------- /aula5/src/__init__.py: -------------------------------------------------------------------------------- 1 | from .config import DBConnection 2 | from .entities import Users as UsersModel 3 | 4 | class UserRepo: 5 | 6 | def insert_user(self, name): 7 | with DBConnection() as db: 8 | new_user = UsersModel(name=name) 9 | db.session.add(new_user) 10 | db.session.commit() 11 | -------------------------------------------------------------------------------- /aula4/src/entities/users.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, String, Integer 2 | from sqlalchemy.sql.expression import true 3 | from src.config import Base 4 | 5 | class Users(Base): 6 | 7 | __tablename__ = "users" 8 | 9 | id = Column(Integer, primary_key=true) 10 | name = Column(String) 11 | 12 | def __repr__(self) -> str: 13 | return f"Users [name={self.name}]" 14 | 15 | -------------------------------------------------------------------------------- /aula5/src/entities/users.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import Column, String, Integer 2 | from sqlalchemy.sql.expression import true 3 | from src.config import Base 4 | 5 | class Users(Base): 6 | 7 | __tablename__ = "users" 8 | 9 | id = Column(Integer, primary_key=true) 10 | name = Column(String) 11 | 12 | def __repr__(self) -> str: 13 | return f"Users [name={self.name}]" 14 | 15 | -------------------------------------------------------------------------------- /aula1/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | cfgv==3.3.0 3 | click==8.0.1 4 | distlib==0.3.2 5 | filelock==3.0.12 6 | Flask==2.0.1 7 | greenlet==1.1.0 8 | identify==2.2.10 9 | itsdangerous==2.0.1 10 | Jinja2==3.0.1 11 | MarkupSafe==2.0.1 12 | nodeenv==1.6.0 13 | pre-commit==2.13.0 14 | PyYAML==5.4.1 15 | six==1.16.0 16 | SQLAlchemy==1.4.19 17 | toml==0.10.2 18 | virtualenv==20.4.7 19 | Werkzeug==2.0.1 20 | -------------------------------------------------------------------------------- /aula2/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | cfgv==3.3.0 3 | click==8.0.1 4 | distlib==0.3.2 5 | filelock==3.0.12 6 | Flask==2.0.1 7 | greenlet==1.1.0 8 | identify==2.2.10 9 | itsdangerous==2.0.1 10 | Jinja2==3.0.1 11 | MarkupSafe==2.0.1 12 | nodeenv==1.6.0 13 | pre-commit==2.13.0 14 | PyYAML==5.4.1 15 | six==1.16.0 16 | SQLAlchemy==1.4.19 17 | toml==0.10.2 18 | virtualenv==20.4.7 19 | Werkzeug==2.0.1 20 | -------------------------------------------------------------------------------- /aula3/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | cfgv==3.3.0 3 | click==8.0.1 4 | distlib==0.3.2 5 | filelock==3.0.12 6 | Flask==2.0.1 7 | greenlet==1.1.0 8 | identify==2.2.10 9 | itsdangerous==2.0.1 10 | Jinja2==3.0.1 11 | MarkupSafe==2.0.1 12 | nodeenv==1.6.0 13 | pre-commit==2.13.0 14 | PyYAML==5.4.1 15 | six==1.16.0 16 | SQLAlchemy==1.4.19 17 | toml==0.10.2 18 | virtualenv==20.4.7 19 | Werkzeug==2.0.1 20 | -------------------------------------------------------------------------------- /aula4/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | cfgv==3.3.0 3 | click==8.0.1 4 | distlib==0.3.2 5 | filelock==3.0.12 6 | Flask==2.0.1 7 | greenlet==1.1.0 8 | identify==2.2.10 9 | itsdangerous==2.0.1 10 | Jinja2==3.0.1 11 | MarkupSafe==2.0.1 12 | nodeenv==1.6.0 13 | pre-commit==2.13.0 14 | PyYAML==5.4.1 15 | six==1.16.0 16 | SQLAlchemy==1.4.19 17 | toml==0.10.2 18 | virtualenv==20.4.7 19 | Werkzeug==2.0.1 20 | -------------------------------------------------------------------------------- /aula4/run.py: -------------------------------------------------------------------------------- 1 | from src import UserRepo 2 | from flask import Flask, request 3 | app = Flask(__name__) 4 | 5 | @app.route("/", methods=["GET"]) 6 | def hello_world(): 7 | return 'Ola, estou na aplicação setada' 8 | 9 | @app.route("/insert", methods=["POST"]) 10 | def insert(): 11 | 12 | userRepo = UserRepo() 13 | body = request.json 14 | 15 | userRepo.insert_user(body["name"]) 16 | 17 | return 'OK' 18 | -------------------------------------------------------------------------------- /aula5/run.py: -------------------------------------------------------------------------------- 1 | from src import UserRepo 2 | from flask import Flask, request 3 | app = Flask(__name__) 4 | 5 | @app.route("/", methods=["GET"]) 6 | def hello_world(): 7 | return 'Ola, estou na aplicação setada' 8 | 9 | @app.route("/insert", methods=["POST"]) 10 | def insert(): 11 | 12 | userRepo = UserRepo() 13 | body = request.json 14 | 15 | userRepo.insert_user(body["name"]) 16 | 17 | return 'OK' 18 | -------------------------------------------------------------------------------- /aula5/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | cffi==1.14.5 3 | cfgv==3.3.0 4 | click==8.0.1 5 | cryptography==3.4.7 6 | distlib==0.3.2 7 | filelock==3.0.12 8 | Flask==2.0.1 9 | greenlet==1.1.0 10 | identify==2.2.10 11 | itsdangerous==2.0.1 12 | Jinja2==3.0.1 13 | MarkupSafe==2.0.1 14 | nodeenv==1.6.0 15 | pre-commit==2.13.0 16 | pycparser==2.20 17 | PyMySQL==1.0.2 18 | PyYAML==5.4.1 19 | six==1.16.0 20 | SQLAlchemy==1.4.19 21 | toml==0.10.2 22 | virtualenv==20.4.7 23 | Werkzeug==2.0.1 24 | -------------------------------------------------------------------------------- /aula5/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | mysqldb: 5 | image: mysql:latest 6 | environment: 7 | - MYSQL_ROOT_PASSWORD=lhama 8 | volumes: 9 | - ./init:/docker-entrypoint-initdb.d 10 | - mysqlVolume:/var/lib/mysql 11 | - mysqlConfig:/etc/mysql 12 | 13 | docker-python: 14 | build: 15 | context: . 16 | ports: 17 | - 3000:5000 18 | depends_on: 19 | - mysqldb 20 | 21 | volumes: 22 | mysqlVolume: 23 | mysqlConfig: 24 | -------------------------------------------------------------------------------- /aula4/src/config/config.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import create_engine 2 | from sqlalchemy.orm import sessionmaker 3 | 4 | class DBConnection: 5 | 6 | def __init__(self) -> None: 7 | self.__connection_string = 'mysql+pymysql://root:lhama@mysqldb/teste' 8 | self.session = None 9 | 10 | def __enter__(self): 11 | engine = create_engine(self.__connection_string) 12 | session_maker = sessionmaker() 13 | self.session = session_maker(bind=engine) 14 | return self 15 | 16 | def __exit__(self, exc_type, exc_val, exc_tb): 17 | self.session.close() -------------------------------------------------------------------------------- /aula5/src/config/config.py: -------------------------------------------------------------------------------- 1 | from sqlalchemy import create_engine 2 | from sqlalchemy.orm import sessionmaker 3 | 4 | class DBConnection: 5 | 6 | def __init__(self) -> None: 7 | self.__connection_string = 'mysql+pymysql://root:lhama@mysqldb/teste' 8 | self.session = None 9 | 10 | def __enter__(self): 11 | engine = create_engine(self.__connection_string) 12 | session_maker = sessionmaker() 13 | self.session = session_maker(bind=engine) 14 | return self 15 | 16 | def __exit__(self, exc_type, exc_val, exc_tb): 17 | self.session.close() --------------------------------------------------------------------------------