4

I got this code from pypi:

from phonenumbers import carrier

ro_number = phonenumbers.parse("+40721234567", "RO")

carrier.name_for_number(ro_number, "en")

Output:

'Vodafone'

I am in India. When I write this code for my phone number it works perfectly and shows Airtel. But my project is on finding the carrier of USA phone number +1xxx xxx xxx. When I do this for a USA number it returns a null string because mapping is not done.

Please help me to do this for US numbers.

Should I change my laptop location? I don't know how to do.

Or should I add pycountry?

Please help me.

Rick M.
  • 3,045
  • 1
  • 21
  • 39
  • 1
    Did you look through the examples here: https://github.com/daviddrysdale/python-phonenumbers – Life is complex Feb 25 '19 at 17:32
  • 1
    from the document: 'For mobile numbers in some countries, you can also find out information about which carrier originally owned a phone number.' – Life is complex Feb 25 '19 at 17:33
  • Added code block, link – Rick M. Feb 26 '19 at 10:39
  • Hi Rick, the number is showing valid for USA number but it is still returning a null string. – Nupur Choudhary Feb 27 '19 at 21:39
  • I have seen the Carrier library too. Maybe data is less. The code inside the library is like. Data= { '4473685': {'en': 'Sky's}, {}, {}, {}...... } Same kind of code for many carrier.. I Can't understand how to add in Library because I don't know how what is 4473685 maybe it is MLS But can't find where to get all the carrier MLS of All USA number so that I could do SMS marketing – Nupur Choudhary Feb 27 '19 at 21:52
  • Can anyone tell me lib phonenumbers in python works for us phone numbers or not?? – Nupur Choudhary Mar 01 '19 at 02:40

1 Answers1

3

Im a little late to this but I found a solution. phonenumbers does not work for US phone numbers. I have written a little script to get carriers from US phone numbers for free. Here it is:

import requests
import json
def getCarrier(number):
    url = 'https://api.telnyx.com/v1/phone_number/1' + number
    html = requests.get(url).text
    data = json.loads(html)
    carrier = data["carrier"]["name"]
    return carrier

All it does is scrape some json from a URL and returns the carrier. Hope someone finds this useful!

Tabulate
  • 611
  • 6
  • 19