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