本文整理汇总了Python中account.Account.find方法的典型用法代码示例。如果您正苦于以下问题:Python Account.find方法的具体用法?Python Account.find怎么用?Python Account.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.Account
的用法示例。
在下文中一共展示了Account.find方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw
# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import find [as 别名]
def draw(uid, currency):
s = current_session()
u = Account.find(uid)
if not u:
raise exceptions.UserNotFound
helpers.require_free_backpack_slot(s, uid)
if currency == 'ppoint':
amount = constants.LOTTERY_PRICE
Account.add_user_credit(u, [('ppoint', -amount)],
exceptions.InsufficientFunds)
elif currency == 'jiecao':
amount = constants.LOTTERY_JIECAO_PRICE
Account.add_user_credit(u, [('jiecao', -amount)],
exceptions.InsufficientFunds)
else:
raise exceptions.InvalidCurrency
reward = random.choice(constants.LOTTERY_REWARD_LIST)
item = Item(owner_id=uid, sku=reward, status='backpack')
s.add(item)
s.flush()
s.add(ItemActivity(
uid=uid, action='lottery', item_id=item.id,
extra=json.dumps({'currency': currency, 'amount': amount}),
created=datetime.datetime.now(),
))
return reward
示例2: get_results
# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import find [as 别名]
def get_results(self, fp=sys.stdout, inline=True):
"""
Fetches the result for the command represented by this object
@param fp: a file object to write the results to directly
"""
result_path = self.meta_data['results_resource']
conn=Qubole.agent()
r = conn.get(result_path , {'inline': inline})
if r.get('inline'):
fp.write(r['results'].encode('utf8'))
else:
acc = Account.find()
boto_conn = boto.connect_s3(aws_access_key_id=acc.storage_access_key,
aws_secret_access_key=acc.storage_secret_key)
log.info("Starting download from result locations: [%s]" % ",".join(r['result_location']))
for s3_path in r['result_location']:
_download_to_local(boto_conn, s3_path, fp)
示例3: buy
# 需要导入模块: from account import Account [as 别名]
# 或者: from account.Account import find [as 别名]
def buy(uid, entry_id):
s = current_session()
u = Account.find(uid)
if not u:
raise exceptions.UserNotFound
entry = s.query(Exchange).filter(Exchange.id == entry_id).first()
if not entry:
raise exceptions.ItemNotFound
seller = entry.seller
if u.ppoint < entry.price:
raise exceptions.InsufficientFunds
helpers.require_free_backpack_slot(s, uid)
u.ppoint -= entry.price
seller.ppoint += entry.price
item = entry.item
s.add(
ItemActivity(
uid=uid,
action="buy",
item_id=entry.item.id,
extra=json.dumps({"seller": seller.id, "price": entry.price}),
created=datetime.datetime.now(),
)
)
item.owner_id = u.id
item.status = "backpack"
s.delete(entry)