Open jburchard opened 5 years ago
@jburchard I've done some phone cleansing and validation recently using phonenumbers. While my work mostly not relevant to Parsons nor does it really fit under the licensing agreements, here's a snippet of code that I wrote that could be helpful to you. It does a couple things:
GB
to US
). If it parses and it's valid, return itPhoneNumberMatcher
and try to extract multiple phone numbers from it, returns all that are validI've found it helpful in dealing with data where users enter multiple phone numbers in the same field (e.g., 5075554323,8005551234
).
def find_phone_numbers(s):
try:
p = phonenumbers.parse(s, "GB")
if phonenumbers.is_valid_number(p):
# it's a singularly valid phone number. Just return it.
# Otherwise, go for the PhoneNumberMatcher
return [p]
except NumberParseException as e:
print(e)
matches = []
for match in phonenumbers.PhoneNumberMatcher(s, "GB"):
# print(match)
if phonenumbers.is_valid_number(match.number):
matches.append(match.number)
return matches
Hey, I'm interested in working on this issue (already talked with @eliotst a bit about it). Let me know if there's anything I should know -- as my starting point, I'm going to look into implementing something similar to what @mklaber describes above. Thanks!
Is someone working on this? I saw this blog post from Twilio about verifying numbers and noticed that it parses pretty reliably too. https://www.twilio.com/blog/2016/02/how-to-verify-phone-numbers-in-python-with-the-twilio-lookup-api.html
Simply calling it and passing a number formatted and some random way will allow you to spit out a standard format.
c = Client(ACCOUNT_SID,AUTH_TOKEN)
number = sys.argv[1]
if number:
checked = c.lookups.phone_numbers(number).fetch()
print(f"{number}\t --> {checked.national_format}")
else:
print("Please specify a phone number.")
Produces:
3192663333 --> (319) 266-3333
+1-319.266.3333 --> (319) 266-3333
319-266-3333 --> (319) 266-3333
(319) 266-3333 --> (319) 266-3333
319 266 3333 --> (319) 266-3333
319-266-3333 --> (319) 266-3333
Nope. That’s really cool, though
On Sun, Sep 27, 2020 at 10:24 AM iamwpj notifications@github.com wrote:
Is someone working on this? I saw this blog post from Twilio about verifying numbers and noticed that it parses pretty reliably too. https://www.twilio.com/blog/2016/02/how-to-verify-phone-numbers-in-python-with-the-twilio-lookup-api.html
Simply calling it and passing a number formatted and some random way will allow you to spit out a standard format.
c = Client(ACCOUNT_SID,AUTH_TOKEN)
number = sys.argv[1]
if number:
checked = c.lookups.phone_numbers(number).fetch() print(f"{number}\t --> {checked.national_format}")
else:
print("Please specify a phone number.")
Produces:
3192663333 --> (319) 266-3333
+1-319.266.3333 --> (319) 266-3333
319-266-3333 --> (319) 266-3333
(319) 266-3333 --> (319) 266-3333
319 266 3333 --> (319) 266-3333
319-266-3333 --> (319) 266-3333
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/move-coop/parsons/issues/28#issuecomment-699649042, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKGDO7IKOY7R57S6TQLCMTSH5KMFANCNFSM4IYA6X2A .
Hi @iamwpj, you are welcome to take this on! Are you in our Slack, by the way? If so, can you ping me there so I can connect your github handle to your name? And if not, would you like to join us?
@shaunagm , i just stumbled across this project and am absolutely ecstatic that this package exists. I would love to be added to the Slack if you guys would have me!!! email is tyler.schlichenmeyer@gmail.com
Like @mklaber, at Movement Labs we use the phonenumbers package regularly for basic phone number validation and normalization. Here's a snippet of our basic use case:
def parse_cell(cell):
try:
return phonenumbers.parse(str(cell), 'US').national_number
except phonenumbers.NumberParseException:
return None
Seems related to #554
I've submitted a pull request that created a format phone numbers. I decided not to use the phonenumbers package because I didn't want to add a new dependency to the mix. I also realized that all the utilities test is in one file. I figured we should break that out into individual files for each method test. https://github.com/move-coop/parsons/pull/928
Some additions to this method could be accepting args for which format you want the number in but I went with E.164 which is the international standard.
We should add in phone number validation/parsing tools.