Skip to content

Instantly share code, notes, and snippets.

View narenaryan's full-sized avatar
🏠
Dreaming Big

N3N9 narenaryan

🏠
Dreaming Big
View GitHub Profile
@narenaryan
narenaryan / fetchone.py
Last active January 10, 2021 18:31
cursor-illu
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
@narenaryan
narenaryan / main.py
Last active January 10, 2021 15:59
cursor-illu
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"
@narenaryan
narenaryan / Dockerfile
Created January 10, 2021 13:08
cursor-tutorial
# 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
@narenaryan
narenaryan / docker-compose.yaml
Last active January 10, 2021 15:59
cursors-tutorial
version: "3.9" # optional since v1.27.0
services:
app:
build: .
depends_on:
- db
environment:
- PYTHONUNBUFFERED=1
db:
image: postgres:latest
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()
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
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
)
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)
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:
from zipfile import ZipFile
from io import BytesIO
def create_zip_v1():
"""
returns: zip archive
"""
archive = BytesIO()
with ZipFile(archive, 'w') as zip_archive: