refacto: rmoved prints and added return in case phone number can't be

parsed
pull/15/head
Sami Mokaddem 2017-12-01 15:52:50 +01:00
parent b1bbb8efc3
commit e4d933a55b
1 changed files with 2 additions and 2 deletions

View File

@ -109,14 +109,15 @@ class Geo_helper:
def getCoordFromPhoneAndPublish(self, phoneNumber, categ): def getCoordFromPhoneAndPublish(self, phoneNumber, categ):
try: try:
print('function accessed')
rep = phonenumbers.parse(phoneNumber, None) rep = phonenumbers.parse(phoneNumber, None)
if not (phonenumbers.is_valid_number(rep) or phonenumbers.is_possible_number(rep)): if not (phonenumbers.is_valid_number(rep) or phonenumbers.is_possible_number(rep)):
print("Phone number not valid") print("Phone number not valid")
return
country_name = geocoder.country_name_for_number(rep, "en") country_name = geocoder.country_name_for_number(rep, "en")
country_code = self.country_to_iso[country_name] country_code = self.country_to_iso[country_name]
if country_code is None: if country_code is None:
print("Non matching ISO_CODE") print("Non matching ISO_CODE")
return
coord = self.country_code_to_coord[country_code.lower()] # countrycode is in upper case coord = self.country_code_to_coord[country_code.lower()] # countrycode is in upper case
coord_dic = {'lat': coord['lat'], 'lon': coord['long']} coord_dic = {'lat': coord['lat'], 'lon': coord['long']}
@ -139,7 +140,6 @@ class Geo_helper:
"cityName": "", "cityName": "",
"regionCode": country_code, "regionCode": country_code,
} }
print(to_send)
self.serv_coord.publish(self.CHANNELDISP, json.dumps(to_send)) self.serv_coord.publish(self.CHANNELDISP, json.dumps(to_send))
except phonenumbers.NumberParseException: except phonenumbers.NumberParseException:
print("Can't resolve phone number country") print("Can't resolve phone number country")