Пример #1
0
def diff_with_backup(predicates, timestamp=afy.settings.start_time, order='first'):
    all_backup_transactions = afy.backup.local.load_before(ynab_api.TransactionDetail, timestamp)
    matching = utils.multi_filter(predicates, all_backup_transactions)

    def key(t):
        return t.id

    # Get the first copy of the transaction saved
    # So that eg default arguments restore state at start of prior run
    unique = utils.by(get_unique(matching, key, order), key)
    unique_keys = set(unique.keys())

    afy.Assistant.download_ynab(transactions=True)  # TODO: can I get away with this?
    current_transactions = utils.by(
        utils.multi_filter(
            predicates,
            afy.Assistant.transactions.values()),
        key)
    current_keys = set(current_transactions.keys())
    modified = unique_keys.intersection(current_keys)
    deleted = unique_keys - current_keys
    added = current_keys - unique_keys
    utils.log_info(
        'Found %s modified, %s deleted, %s added transactions' %
        (len(modified), len(deleted), len(added)))
    return [list(filter(lambda t: t.id in x, matching)) for x in (modified, deleted, added)]
Пример #2
0
def get_eligible_transactions(transactions):
    utils.log_debug('get_eligible_transactions')
    predicates = newer_than, has_blank_or_WIP_memo, matches_account
    eligible = utils.multi_filter(predicates, transactions)
    utils.log_info(
        'Found %s transactions to attempt to match with Amazon orders' %
        len(eligible))
    return utils.by(eligible, lambda t: t.id)
Пример #3
0
 def make_get_by_name(self):
     grouped = utils.group_by(self.xs, self.name)
     self.names = utils.by(map(lambda v: v.pop(), grouped.values()),
                           self.name)
     for name, g in grouped.items():
         if g:
             utils.log_debug('duplicate name, using first', name,
                             self.names[name], *g)
Пример #4
0
def enqueue(xs, queue):
    utils.log_debug('enqueue', xs, queue)
    xs = utils.copy(xs)

    has_id = list(filter(lambda x: x.id is not None, xs))
    assert len(set(map(lambda x: x.id, has_id))) == len(has_id)
    queue.update(utils.by(xs, lambda x: x.id))

    null_id = list(filter(lambda x: x.id is None, xs))
    if null_id:
        if None not in queue:
            queue[None] = []
        queue[None].extend(null_id)
Пример #5
0
 def store(self, xs):  # TODO listy?
     self.xs = self.filter(xs)
     self.ids = utils.by(self.xs, self.id)
     self.make_get_by_name()
     self.history.append(self.xs)