本文整理汇总了Python中transaction.Transaction.obligation_to_user方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.obligation_to_user方法的具体用法?Python Transaction.obligation_to_user怎么用?Python Transaction.obligation_to_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction.Transaction
的用法示例。
在下文中一共展示了Transaction.obligation_to_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sum_obligations
# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import obligation_to_user [as 别名]
def sum_obligations(messages, user_id):
balances = defaultdict(float)
errors = list()
for m in messages:
try:
t = Transaction(m)
value, party = t.obligation_to_user(user_id)
balances[party] += value
except TransactionParseError as err:
errors.append(err)
return balances, errors
示例2: status_for_user
# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import obligation_to_user [as 别名]
def status_for_user(user_id, show_unparsed=False):
user_list = users()
balances = defaultdict(float)
unparsed = list()
messages = transactions(user_id)
for m in messages:
transaction = Transaction(m.get('text'))
if transaction.parsed:
value, party = transaction.obligation_to_user(user_id)
balances[party] += value
else:
unparsed.append(m.get('text'))
response = response_for_balances(balances, user_list)
if show_unparsed and len(unparsed):
response += "\n" + \
"\n".join(["unabled to parse message: %s" % m for m in unparsed])
total_value = sum(b for b in balances.values())
decorator = decoration_for_balance(total_value)
preamble = "%s status for %s %s\n" % (
decorator, user_name_for_id(user_id, user_list), decorator)
return preamble + response