Esempio n. 1
0
    def get_next_avail_number(self):
        """
        Returns the next available number that we own. If none are available, buys it from Twilio.
        """
        area_code = int(self.conf['twilio_area_code'])
        numbers = [
            vbts_util.strip_number(str(n.phone_number))
            for n in self.twilio_client.phone_numbers.list()
        ]
        avail_numbers = vbts_util.get_next_avail_number(numbers)
        if (len(avail_numbers) == 0):
            # if we have none, get a new number
            new_numbers = self.twilio_client.phone_numbers.search(
                area_code=area_code)
            if not new_numbers:
                raise ValueError("No numbers available in area code %d" %
                                 area_code)
            num = new_numbers[0]
            if not num.purchase():  # this does the buy!
                raise ValueError("Purchasing number failed")
            # setup new number
            bought_num = self.twilio_client.phone_numbers.list(
                phone_number=num.phone_number)[0]
            bought_num.update(
                sms_url=self.conf['twilio_sms_url'],
                voice_url=self.conf['twilio_voice_url'],
                sms_fallback_url=self.conf['twilio_sms_fallback_url'],
                voice_method=self.conf['twilio_voice_method'],
                sms_method=self.conf['twilio_sms_method'],
                sms_fallback_method=self.conf['twilio_sms_fallback_method'])
            avail_numbers.append(
                vbts_util.strip_number(str(bought_num.phone_number)))

        return random.choice(avail_numbers)
Esempio n. 2
0
 def get_next_avail_number(self):
     nums = []
     file_loc = self.conf['voipms_fileloc']
     f = open(file_loc, 'r')
     for l in f:
         nums.append(l.strip())
     nums = vbts_util.get_next_avail_number(nums)
     if (len(nums) == 0):
         raise ValueError("Not enough voip.ms numbers")
     return random.choice(nums)
 def get_next_avail_number(self):
     nums = []
     file_loc = self.conf['voipms_fileloc']
     f = open(file_loc, 'r')
     for l in f:
         nums.append(l.strip())
     nums = vbts_util.get_next_avail_number(nums)
     if (len(nums) == 0):
         raise ValueError("Not enough voip.ms numbers")
     return random.choice(nums)
 def get_next_avail_number(self):
     """
     Returns the next available number that we own. If none are available, buys it from nexmo.
     """
     area_code = int(self.conf['twilio_area_code'])
     numbers = [vbts_util.strip_number(str(n)) for n in self.__get_existing_numbers()]
     avail_numbers = vbts_util.get_next_avail_number(numbers)
     if (len(avail_numbers) == 0):
         target = self.__search_numbers()
         if (self.__buy_number(target)):
             avail_numbers.append(str(target))
         else:
             raise ValueError("Purchasing number failed")
     return random.choice(avail_numbers)
    def get_next_avail_number(self):
        """
        Returns the next available number that we own. If none are available, buys it from Twilio.
        """
        area_code = int(self.conf['twilio_area_code'])
        numbers = [vbts_util.strip_number(str(n.phone_number)) for n in self.twilio_client.phone_numbers.list()]
        avail_numbers = vbts_util.get_next_avail_number(numbers)
        if (len(avail_numbers) == 0):
            # if we have none, get a new number
            new_numbers = self.twilio_client.phone_numbers.search(area_code=area_code)
            if not new_numbers:
                raise ValueError("No numbers available in area code %d" % area_code)
            num = new_numbers[0]
            if not num.purchase(): # this does the buy!
                raise ValueError("Purchasing number failed")
            # setup new number
            bought_num = self.twilio_client.phone_numbers.list(phone_number=num.phone_number)[0]
            bought_num.update(sms_url=self.conf['twilio_sms_url'], voice_url=self.conf['twilio_voice_url'], sms_fallback_url=self.conf['twilio_sms_fallback_url'], voice_method=self.conf['twilio_voice_method'], sms_method=self.conf['twilio_sms_method'], sms_fallback_method=self.conf['twilio_sms_fallback_method'])
            avail_numbers.append(vbts_util.strip_number(str(bought_num.phone_number)))

        return random.choice(avail_numbers)