신호생성 repo (24. 1. 5 ~).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

48 lines
1.9 KiB

import pyodbc, os, csv
# 현재 스크립트가 포함된 폴더 지정
path_present = os.path.dirname(os.path.abspath(__file__))
# 접속정보
DSNNAME = "Tibero6"
DBUSER = "snits"
DBPWD = "snitsUIspxmworks#PW"
cnxn = pyodbc.connect(f'DSN={DSNNAME};UID={DBUSER};PWD={DBPWD};charset=utf-8')
cursor = cnxn.cursor()
# 스키마 및 테이블명
schema = 'SNMS'
tables = ['TC_IF_TOD_DAY_PLAN', # TOD 일계획 현황
'TC_IF_TOD_HOLIDAY_PLAN', # TOD 휴일 계획
'TC_IF_TOD_RED_YELLO', # TOD 적색 및 황색 시간
'TC_IF_TOD_WEEK_PLAN', # TOD 주 계획
# 'TL_IF_SIGL', # 신호 운영 이력 (5초)
# 'TL_IF_SIGL_CYCL', # 신호 운영 주기 이력 (5분)
'TM_FA_CRSRD', # 교차로 마스터
'TN_IF_SIGL_FLOW', # 신호 현시 별 이동류 방향
]
# 테이블 불러오는 함수
def fetch_table(table, condition=""):
try:
query = f"SELECT * FROM {schema}.{table} {condition}"
cursor.execute(query)
csv_file_path = os.path.join(path_present, f"{table}.csv")
with open(csv_file_path, 'w', newline='', encoding='utf-8-sig') as csvfile:
csv_writer = csv.writer(csvfile)
columns = [column[0] for column in cursor.description]
csv_writer.writerow(columns)
for row in cursor.fetchall():
csv_writer.writerow(row)
except Exception as e:
print(f"오류 발생: {e}")
# 신호이력을 제외한 테이블들 불러오기
for table in tables:
fetch_table(table)
# 초단위 신호이력 불러오기
fetch_table('TL_IF_SIGL', condition="WHERE TRUNC(PHASE_DT) = TO_DATE('2024-07-31', 'YYYY-MM-DD') AND CRSRD_ID IN (436, 437, 438, 442, 443, 444, 455, 456, 457, 458)")
# 주기단위 신호이력 불러오기
fetch_table('TL_IF_SIGL_CYCL', condition="WHERE TRUNC(OCRN_DT) = TO_DATE('2024-07-31', 'YYYY-MM-DD') AND CRSRD_ID IN (436, 437, 438, 442, 443, 444, 455, 456, 457, 458)")