示例#1
0
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
0
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