Skip to content

Instantly share code, notes, and snippets.

@rakjin
Created June 12, 2015 12:30
Show Gist options
  • Save rakjin/9ded3f99893ee655bbc2 to your computer and use it in GitHub Desktop.
Save rakjin/9ded3f99893ee655bbc2 to your computer and use it in GitHub Desktop.
tz to ccc
전화번호를 정규화하자
목표: plivo에서 받는 형식(국가번호로 시작하며, 숫자로만 이루어진 번호)으로 변환하자
if n.starts_with(+):
return strip_signs(n)
n = stript_signs(n)
ccc = tz_to_ccc(invitation.TZ_NAME) # 초대장의 타임존 정보를 통해 국가 번호를 유추합니다. => 바로는 불가능. 타임존 당 국가번호가 여러개인 경우가 많음.
# https://countrycode.org, https://github.com/eggert/tz/blob/master/zone.tab
# 이걸 통해 타임존 => 국가코드 => 국가번호로 변환. (하지만 이것도 정확한 것은 아님. 일단 타임존=>국가코드 매칭이 M:N임...)
if n.starts_with(ccc):
return n
while n.starts_with(0): # NANP의 경우 0으로 시작하면 invalid
n = remove_initial_zero(n)
return ccc + n
이러면 북미국가들과 한국은 커버 되는데 다른 국가는 잘 모르겠다.
http://en.wikipedia.org/wiki/North_American_Numbering_Plan
## 기능이 과하게 많고, 특히 데이터가 너무 큼. 안쓰는걸로.
https://github.com/googlei18n/libphonenumber
https://github.com/daviddrysdale/python-phonenumbers
결론: 사용자로부터 명시적으로 입력받아야한다. 그것만이 살길이다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment