本文整理汇总了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)
示例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)
示例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()