This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with connect(**config) as conn: | |
| with conn.cursor() as cur: | |
| cur.execute(sql_query, ["John%"]) | |
| res = [row for row in cur.fetchone()] | |
| # You only get one row at max |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from psycopg2 import connect | |
| import time | |
| # Get this from ENV variables or configuration store | |
| config = { | |
| "host": "db", | |
| "dbname": "dvdrental", | |
| "user": "postgres", | |
| "password": "mypassword", | |
| "port": "5432" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # set base image | |
| FROM python:3.8-slim | |
| # set the working directory in the container | |
| WORKDIR /app | |
| # copy the dependencies file to temp directory | |
| COPY app/requirements.txt /tmp/ | |
| # install dependencies |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.9" # optional since v1.27.0 | |
| services: | |
| app: | |
| build: . | |
| depends_on: | |
| - db | |
| environment: | |
| - PYTHONUNBUFFERED=1 | |
| db: | |
| image: postgres:latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile, ZipInfo | |
| from io import BytesIO | |
| def delete(path): | |
| """ | |
| Param: path -> file in archive | |
| Returns a new zip file after deleting path | |
| """ | |
| new_zip = BytesIO() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile, ZipInfo | |
| from io import BytesIO | |
| def update_or_insert(path, data): | |
| """ | |
| Param: path -> file in archive | |
| Param: data -> data to be updated | |
| Returns a new zip file with the updated content |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile | |
| with ZipFile('config.zip', 'w') as zip_archive: | |
| zip_archive.writestr( | |
| 'docker/docker-compose.yaml', # File to replace | |
| b'docker-compose-file-content-new' # Data | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile | |
| docker_compose_config = None | |
| with ZipFile('config.zip') as zip_archive: | |
| docker_compose_config = zip_archive.read('config/docker/docker-compose.yaml') | |
| print(docker_compose_config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile, ZipInfo | |
| from io import BytesIO | |
| def create_zip_v2(): | |
| """ | |
| returns: zip archive | |
| """ | |
| archive = BytesIO() | |
| with ZipFile(archive, 'w') as zip_archive: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from zipfile import ZipFile | |
| from io import BytesIO | |
| def create_zip_v1(): | |
| """ | |
| returns: zip archive | |
| """ | |
| archive = BytesIO() | |
| with ZipFile(archive, 'w') as zip_archive: |