기본파일
This commit is contained in:
32
conf/config.sample.yaml
Normal file
32
conf/config.sample.yaml
Normal file
@ -0,0 +1,32 @@
|
||||
# 데이터베이스 접속 정보
|
||||
database:
|
||||
host: localhost # DB 호스트명 (docker-compose에서 사용하는 서비스명 mariadb)
|
||||
user: YOUR_DB_USER # DB 사용자명
|
||||
password: YOUR_DB_PASS # DB 비밀번호
|
||||
name: YOUR_DB_NAME # 사용할 데이터베이스 이름
|
||||
|
||||
# 기상청 API 설정
|
||||
weather_api:
|
||||
service_key: YOUR_WEATHER_API_KEY # 기상청 API 서비스 키 (초단기예보, 단기예보 등)
|
||||
|
||||
# 대기환경 API 설정
|
||||
air_quality_api:
|
||||
service_key: YOUR_AIR_QUALITY_API_KEY # 대기환경정보 API 서비스 키 (예: 미세먼지 농도)
|
||||
|
||||
# GA4 설정
|
||||
ga4:
|
||||
token: YOUR_GA4_TOKEN
|
||||
property_id: 123456789 # 숫자만 입력
|
||||
|
||||
# 테이블 접두어 정의
|
||||
table_prefix: fg_manager_static_
|
||||
|
||||
# 테이블명 정의 (접두어 제외)
|
||||
tables:
|
||||
air: air
|
||||
weather: weather
|
||||
ga4: ga4
|
||||
pos: pos
|
||||
pos_deactivate: pos_deactivate
|
||||
|
||||
debug: false # 디버그 모드 여부 (true/false)
|
||||
0
lib/__init__.py
Normal file
0
lib/__init__.py
Normal file
21
lib/db.py
Normal file
21
lib/db.py
Normal file
@ -0,0 +1,21 @@
|
||||
# db.py
|
||||
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
import yaml
|
||||
|
||||
def load_config(path='conf/config.yaml'):
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
return yaml.safe_load(f)
|
||||
|
||||
config = load_config()
|
||||
db_cfg = config['database']
|
||||
|
||||
db_url = f"mysql+pymysql://{db_cfg['user']}:{db_cfg['password']}@{db_cfg['host']}/{db_cfg['name']}?charset=utf8mb4"
|
||||
|
||||
# MySQL 연결이 끊겼을 때 자동 재시도
|
||||
engine = create_engine(db_url, pool_pre_ping=True)
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
def get_session():
|
||||
return Session()
|
||||
16
lib/db_schema.py
Normal file
16
lib/db_schema.py
Normal file
@ -0,0 +1,16 @@
|
||||
# lib/db_schema.py
|
||||
from sqlalchemy import Table, Column, Date, Float, MetaData
|
||||
|
||||
metadata = MetaData()
|
||||
|
||||
fg_manager_static_air = Table(
|
||||
'fg_manager_static_air',
|
||||
metadata,
|
||||
Column('date', Date, primary_key=True, nullable=False),
|
||||
Column('pm25', Float),
|
||||
Column('pm10', Float),
|
||||
Column('so2', Float),
|
||||
Column('co', Float),
|
||||
Column('no2', Float),
|
||||
Column('o3', Float),
|
||||
)
|
||||
Reference in New Issue
Block a user