当前位置: 首页>>代码示例>>Python>>正文


Python Subscriber.get方法代码示例

本文整理汇总了Python中subscriber.Subscriber.get方法的典型用法代码示例。如果您正苦于以下问题:Python Subscriber.get方法的具体用法?Python Subscriber.get怎么用?Python Subscriber.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subscriber.Subscriber的用法示例。


在下文中一共展示了Subscriber.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: validate_data

# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import get [as 别名]
 def validate_data(self, pin):
     res_log.debug('Check PIN length')
     if len(pin) > 4 or len(pin) < 4:
         raise ResellerException('PIN invalid length')
 
 
     res_log.debug('Check if Reseller exists')
     # check if reseller exists in the database and the PIN is valid
     try:
         cur = db_conn.cursor()
         cur.execute('SELECT msisdn,pin FROM resellers WHERE msisdn=%(msisdn)s', {'msisdn': str(self.reseller_msisdn)})
         if cur.rowcount > 0:
             res_log.debug('Valid Reseller found')
             res_log.debug('Auth PIN')
             data = cur.fetchone()
             if data[1] != pin:
                 raise ResellerException('Invalid PIN!')
             res_log.debug('Check if subscriber is valid')
             # check if subscriber exists
             try:
                 sub = Subscriber()
                 sub.get(self.subscriber_msisdn)
             except SubscriberException as e:
                 raise ResellerException('Invalid subscriber')
     
         else:
             raise ResellerException('Invalid Reseller')
     except psycopg2.DatabaseError as e:
         raise ResellerException('Database error getting reseller msisdn: %s' % e)
开发者ID:Rhizomatica,项目名称:rccn,代码行数:31,代码来源:reseller.py

示例2: add

# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import get [as 别名]
    def add(self, msisdn, pin, balance):
        # check if subscriber exists
        try:
            sub = Subscriber()
            sub.get(msisdn)
        except SubscriberException as e:
            raise ResellerException('Invalid subscriber: %s' % e)

        # provision the reseller
        try:
            cur = db_conn.cursor()
            cur.execute('INSERT INTO resellers(msisdn,pin,balance) VALUES(%(msisdn)s,%(pin)s,%(balance)s)', {'msisdn': msisdn, 'pin': pin, 'balance': Decimal(str(balance))})
            db_conn.commit()
        except psycopg2.DatabaseError as e:
            raise ResellerException('PG_HLR error provisioning reseller: %s' % e)
开发者ID:Rhizomatica,项目名称:rccn,代码行数:17,代码来源:reseller.py

示例3: add

# 需要导入模块: from subscriber import Subscriber [as 别名]
# 或者: from subscriber.Subscriber import get [as 别名]
    def add(self, msisdn, credit):
        sub = Subscriber()
        sms = SMS();
        try:
            mysub = sub.get(msisdn)
        except SubscriberException as e:
            raise CreditException(e)

        current_balance = sub.get_balance(msisdn)
        new_balance = Decimal(str(credit)) + Decimal(str(current_balance))

        # update subscriber balance
        try:
            cur = db_conn.cursor()
            cur.execute('UPDATE subscribers SET balance=%(new_balance)s WHERE msisdn=%(msisdn)s', {'new_balance': Decimal(str(new_balance)), 'msisdn': msisdn})
            sms.send(config['smsc'], msisdn, sms_credit_added % (credit, new_balance))
        except psycopg2.DatabaseError as e:
            raise CreditException('PG_HLR error updating subscriber balance: %s' % e)

        # insert transaction into the credit history
        try:
            cur = db_conn.cursor()
            cur.execute('INSERT INTO credit_history(msisdn,previous_balance,current_balance,amount) VALUES(%s,%s,%s,%s)', (msisdn, current_balance, new_balance, credit))
        except psycopg2.DatabaseError as e:
            db_conn.rollback()
            raise CreditException('PG_HLR error inserting invoice in the history: %s' % e)
        finally:
            db_conn.commit()
开发者ID:ciaby,项目名称:rccn,代码行数:30,代码来源:credit.py


注:本文中的subscriber.Subscriber.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。