Initial commit: Excel Address to Postal Code Converter

This commit is contained in:
2026-05-26 22:38:52 +09:00
commit b91d8b8fac
8 changed files with 542 additions and 0 deletions

108
main.py Normal file
View File

@@ -0,0 +1,108 @@
#!/usr/bin/env python3
"""
엑셀 파일의 주소에서 우편번호를 조회하여 추가하는 애플리케이션
"""
import sys
import os
from pathlib import Path
from address_handler import AddressLookup
from excel_handler import ExcelHandler
def main():
"""메인 함수"""
print("=" * 60)
print("엑셀 주소 → 우편번호 자동 변환 앱")
print("=" * 60)
print()
# 파일 경로 입력
if len(sys.argv) > 1:
file_path = sys.argv[1]
else:
file_path = input("처리할 엑셀 파일 경로를 입력하세요: ").strip()
# 파일 확인
if not os.path.exists(file_path):
print(f"✗ 파일을 찾을 수 없습니다: {file_path}")
return False
if not file_path.endswith(('.xlsx', '.xls')):
print("✗ 엑셀 파일(.xlsx 또는 .xls)만 지원합니다")
return False
print()
# 1. 엑셀 파일 열기
excel = ExcelHandler(file_path)
if not excel.open_file():
return False
print()
# 2. 주소 읽기
addresses = excel.get_addresses()
if addresses is None or len(addresses) == 0:
print("✗ 처리할 주소가 없습니다")
excel.close_file()
return False
print()
# 3. 네이버 API 초기화
try:
lookup = AddressLookup()
except ValueError as e:
print(f"{str(e)}")
excel.close_file()
return False
print()
print("주소에서 우편번호 조회 중...")
print("-" * 60)
# 4. 우편번호 조회
postal_codes = lookup.get_postal_codes_batch(addresses)
print()
print("-" * 60)
print()
# 5. 우편번호 추가
excel.add_postal_codes(postal_codes)
# 조회 결과 통계
successful = sum(1 for v in postal_codes.values() if v)
failed = len(postal_codes) - successful
print()
print("-" * 60)
print(f"조회 결과: 성공 {successful}개, 실패 {failed}")
print("-" * 60)
print()
# 6. 파일 저장
if excel.save_file():
print()
print("=" * 60)
print("✓ 처리 완료!")
print("=" * 60)
excel.close_file()
return True
else:
excel.close_file()
return False
if __name__ == '__main__':
try:
success = main()
sys.exit(0 if success else 1)
except KeyboardInterrupt:
print("\n\n중단되었습니다.")
sys.exit(1)
except Exception as e:
print(f"\n✗ 예상치 못한 오류: {str(e)}")
sys.exit(1)