79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
기존 Person 데이터의 전화번호를 대시 없는 형태로 업데이트하는 스크립트
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import django
|
|
import re
|
|
|
|
# Django 설정
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'A_core.settings')
|
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
django.setup()
|
|
|
|
from B_main.models import Person
|
|
|
|
def format_phone_number(phone):
|
|
"""전화번호에서 숫자만 추출하여 반환"""
|
|
if not phone:
|
|
return phone
|
|
# 숫자만 추출
|
|
numbers = re.sub(r'[^0-9]', '', phone)
|
|
|
|
# 11자리인 경우에만 반환
|
|
if len(numbers) == 11 and numbers.startswith('010'):
|
|
return numbers
|
|
elif len(numbers) == 10 and numbers.startswith('010'):
|
|
return numbers
|
|
|
|
return phone
|
|
|
|
def update_phone_numbers():
|
|
"""기존 Person 데이터의 전화번호를 대시 없는 형태로 업데이트"""
|
|
print("=" * 60)
|
|
print("Person 데이터 전화번호 업데이트")
|
|
print("=" * 60)
|
|
|
|
# 모든 Person 데이터 조회
|
|
persons = Person.objects.all()
|
|
|
|
updated_count = 0
|
|
for person in persons:
|
|
if person.연락처:
|
|
old_phone = person.연락처
|
|
new_phone = format_phone_number(old_phone)
|
|
|
|
if old_phone != new_phone:
|
|
print(f"업데이트: {person.이름} - {old_phone} → {new_phone}")
|
|
person.연락처 = new_phone
|
|
person.save()
|
|
updated_count += 1
|
|
else:
|
|
print(f"변경 없음: {person.이름} - {old_phone}")
|
|
else:
|
|
print(f"전화번호 없음: {person.이름}")
|
|
|
|
print(f"\n총 {updated_count}개의 전화번호가 업데이트되었습니다.")
|
|
|
|
# 중복 확인
|
|
print("\n중복 전화번호 확인:")
|
|
phone_counts = {}
|
|
for person in Person.objects.all():
|
|
if person.연락처:
|
|
phone_counts[person.연락처] = phone_counts.get(person.연락처, 0) + 1
|
|
|
|
duplicates = {phone: count for phone, count in phone_counts.items() if count > 1}
|
|
if duplicates:
|
|
print("중복된 전화번호 발견:")
|
|
for phone, count in duplicates.items():
|
|
print(f" {phone}: {count}개")
|
|
persons_with_phone = Person.objects.filter(연락처=phone)
|
|
for person in persons_with_phone:
|
|
print(f" - {person.이름} (ID: {person.id}, 회원가입상태: {person.회원가입상태})")
|
|
else:
|
|
print("중복된 전화번호가 없습니다.")
|
|
|
|
if __name__ == '__main__':
|
|
update_phone_numbers() |