Skip to main content

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

Metadata

Release files for atzlib 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atzlib 0.1.3
File Size Uploaded
atzlib-0.1.3.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for atzlib 0.1.3
File Interpreter ABI Platform
atzlib-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 22.9 kB

Release files / atzlib-0.1.3.tar.gz

Download URL atzlib-0.1.3.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
888d40acea3b0d751a80fd59693f61d444e1ab7d5a9fbe1796662dec3c9cf264
BLAKE2b-256 checksum
How to use checksums
df11ae7cda440a7fa40633cc514bf6c692be8c60ef687d5daf2ec73b9c409fa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0

Release files / atzlib-0.1.3-py3-none-any.whl

Download URL atzlib-0.1.3-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18ed3f8b6ddd4a923d9eb42bff5f8ad41866d749f467d2787982174dbf29a360
BLAKE2b-256 checksum
How to use checksums
f4e3ca7e35eeb6ddafb391f4db6378554bc643a0c66a1a277893bceb996552d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.4 Darwin/23.6.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page