Ejemplo n.º 1
0
 def deactivate_subscriptions(self, msg):
     try:
         sms = SMS()
         sub = Subscriber()
         cur = db_conn.cursor()
         cur.execute(
             'SELECT msisdn FROM subscribers WHERE subscription_status = 0 AND authorized = 1'
         )
         count = cur.rowcount
         if count > 0:
             self.logger.info('Found %d subscribers to be deactivated' %
                              count)
             subscribers_list = cur.fetchall()
             db_conn.commit()
             for mysub in subscribers_list:
                 self.logger.debug(
                     'Send SMS that account is deactivated to %s' %
                     mysub[0])
                 sms.send(config['smsc'], mysub[0], msg)
                 # disable subscriber
                 try:
                     sub.authorized(mysub[0], 0)
                 except SubscriberException as e:
                     raise SubscriptionException(
                         'PG_HLR error in deactivating subscription: %s' %
                         e)
         else:
             db_conn.commit()
             self.logger.info('No subscribers need to be deactivate')
     except psycopg2.DatabaseError as e:
         raise SubscriptionException(
             'PG_HLR error in checking subscriptions to deactivate: %s' % e)
Ejemplo n.º 2
0
 def put(self,
         request,
         msisdn='',
         name='',
         balance='',
         authorized='',
         subscription_status='',
         location='',
         equipment='',
         roaming='',
         package=''):
     api_log.info(
         '%s - [PUT] %s/%s Data: name:"%s" balance:"%s" authorized:"%s" '
         'subscription_status:"%s" location:"%s" equipment:"%s" roaming:"%s" package:"%s"',
         request.getHost().host, self.path, msisdn, name, balance,
         authorized, subscription_status, location, equipment, roaming,
         package)
     try:
         sub = Subscriber()
         if subscription_status != '':
             sub.subscription(msisdn, subscription_status)
         if authorized != '':
             sub.authorized(msisdn, authorized)
         if msisdn != '' and name != '' or balance != '':
             sub.edit(msisdn, name, balance, location, equipment, roaming,
                      package)
         data = {'status': 'success', 'error': ''}
     except SubscriberException as e:
         data = {'status': 'failed', 'error': str(e)}
     api_log.info(data)
     return data