Skip to main content

My python codes.

Project description

atzlib

Bunch of python codes. Test project to learn how to manage pypi library.

LINK: https://pypi.org/manage/project/atzlib/releases/

poetry config pypi-token.pypi your-pypi-token

TODO: 코드 작동 확인 및 서브패키지 분리하기

기능목록

ezpsql.py

def upload_csv(file_path, table_name, primary_keys, foreign_keys=None, reset=False):
    """
    CSV 파일에서 데이터를 로드하여 데이터베이스에 업로드합니다.

    Args:
        file_path (str): CSV 파일의 경로.
        table_name (str): 생성하거나 업서트할 테이블 이름.
        primary_keys (list of str): 기본 키 컬럼들.
        foreign_keys (dict, optional): 컬럼 이름과 외래 키 참조를 매핑하는 딕셔너리.
        reset (bool, optional): 업서트 전에 테이블을 초기화할지 여부. 기본값은 False.
    """

사용방법

1. config.yaml 파일을 수정해서 연결정보 저장

# config.yaml template
database:
  user: YOUR_NAME
  password: YOUR_PASSWORD
  host: YOUR_HOSTID
  port: 5432
  dbname: YOUR_DBNAME

2. ezpsql.py를 임포트하여 데이터 업로드

from ezpsql import upload_csv
upload_csv('test.csv', 'test', primary_keys=['SEQ_NO'])

3. 연결 및 데이터 쿼리 방법

from ezpsql import connect_db
from sqlalchemy import text
import pandas as pd

engine = connect_db()
query = text('SELECT * FROM public.tms_elite_temp WHERE "TR_ID" LIKE :tr_id')
reg_map = pd.read_sql_query(query, engine, params={'tr_id': '%수원%'})
reg_map

일일 스케쥴러 작성방법

1. 노트북 -> .py

if __name__ == "__main__":

구문을 사용하여 구동되는 .py로 변경

예시

#!/usr/bin/env python
# coding: utf-8

from ezpsql import upload_csv
from ezpsql import connect_db

from sqlalchemy import text
import pandas as pd


if __name__ == "__main__":
    upload_csv('test.csv', 'test', primary_keys=['DEV_ID'], option=['reset'])
    engine = connect_db()
    query = text('SELECT * FROM public.test')
    reg_map = pd.read_sql_query(query, engine)

2. 실행파일 동작확인

python main.py

3. bash 스케쥴러 작성

#!/bin/bash
while true
do
    echo "Running Python script at $(date)"
    python /path/to/your/main.py
    sleep 86400  # 86400초 = 24시간
done

4. .sh 권한부여 및 실행

chmod +x run_daily.sh
./run_daily.sh

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atzlib-0.1.2.tar.gz (94.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

atzlib-0.1.2-py3-none-any.whl (94.7 MB view details)

Uploaded Python 3

File details

Details for the file atzlib-0.1.2.tar.gz.

File metadata

  • Download URL: atzlib-0.1.2.tar.gz
  • Upload date:
  • Size: 94.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0

File hashes

Hashes for atzlib-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ba7df0a713cc93d287e206b0a7420c788ea72a21817438fcea30a3307366003a
MD5 2bda6396f37e44e9f8931106e7f9202b
BLAKE2b-256 de84ee289b1606309822464084c58247b0edbd686b49a27e157787f9d37fdf3b

See more details on using hashes here.

File details

Details for the file atzlib-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: atzlib-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 94.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0

File hashes

Hashes for atzlib-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9d0bd250d0e0d3014bdebafe6ccf029d6bd514d62ef44fcf683fdf0b34c00fd3
MD5 1ffb6368a3a18764a5173b2142c3a782
BLAKE2b-256 cfac2e09cef03d1da93507e2b0300265487b2064a4e05a5b58db70972abc521a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page