<commit_before>#! /usr/bin/env python3
"""OFX file parsing."""

from __future__ import print_function

from datetime import datetime
import hashlib
from ofxtools import OFXTree
import sys

from pyledgertools.rule_parser import walk_rules

now = datetime.now
strftime = datetime.strftime

CURRENCY_LOOKUP = {
    'USD': '$',
}
"""Dictoinary for converting ofx currency string to a proper symbol."""

def make_tag_string(tags, indent):
    t = ':'.join([x for x in tags])
    return '{}; :{}:'.format(indent, t)


def make_meta_string(metadata, indent):
    """Convert list of metadata lists into a string.

    Parameters:
        metadata (list): List of list pairs (key, value)
        indent (str): String used for indentation.

    Returns:
        str: Returns a metadata string suitable for a ledger-cli journal.

    >>> make_meta_string([['key1', 'value1'], ['key2', 'value2']], '  ')
    "  ; key1: value1\\n  ; key2: value2"
    """
    m = []
    for meta in metadata:
        m.append('{}; {}: {}'.format(indent, meta[0], meta[1]))

    return '\n'.join(m)


class Allocation(object):
    """Allocation class for transactions.

    Attributes:
        account (str): Name of the ledger account for this allocation.
        amount (float): Dollar value of the allocation.
        currency (str): String representing the allocation commodity.
            ``$``, ``USD``, ``CAN`` etc.
        assertion (bool): Set to `True` if allocation is a balance assertion.
            Allocation will be represented as:
            ::

            <account>                                      = <currency> <amount>

            Instead of:
            ::

            <account>                                        <currency> <amount>
        tags (list): Tag strings to add to the allocation.
        metadata (list): Key/value pairs to add to allocation.
    """

    def __init__(self, **kwargs):
        """Initialize allocation.

        Parameters:
            account (str): Name of the ledger account for this allocation.
            amount (float): Dollar value of the allocation.
            currency (str): String representing the allocation commodity.
            assertion (bool): Set to 'True' if allocation is balance assertion.
            tags (list): Tag strings to add to the allocation.
            metadata (list): Key/value pairs to add to allocation.
        """
        self.account = kwargs['account']
        self.amount = kwargs['amount']
        self.currency = kwargs.get('currency', '$')
        self.assertion = kwargs.get('assertion', False)
        self.tags = kwargs.get('tags', [])
        self.metadata = kwargs.get('metadata', [])

    def to_string(self, width=80, indent=4):
        """ Allocation as string. Fix to width in this.

        Keyword Args:
            width (int): White space added after allocation acount to align last
                digit of 'amount' to column `width`.
            indent (int): Number of spaces to indent each level of transaction.

        Return:
            str: Ledger-cli formatted string for the allocation.
        """

        ind = ' ' * indent
        acct = self.account
        if self.assertion:
            amt = '= {} {:.2f}'.format(self.currency, self.amount)
        else:
            amt = '{} {:.2f}'.format(self.currency, self.amount)

        # Calculate fill, split amount at decimal to align to decimal.
        fill = ' ' * (width - len(acct + amt.split('.')[0] + ind + 3))

        outlist = []
        outlist.append(ind + acct + fill + amt)
<commit_msg>Fix incorrect syntax.<commit_after>#! /usr/bin/env python3
"""OFX file parsing."""

from __future__ import print_function

from datetime import datetime
import hashlib
from ofxtools import OFXTree
import sys

from pyledgertools.rule_parser import walk_rules

now = datetime.now
strftime = datetime.strftime

CURRENCY_LOOKUP = {
    'USD': '$',
}
"""Dictoinary for converting ofx currency string to a proper symbol."""

def make_tag_string(tags, indent):
    t = ':'.join([x for x in tags])
    return '{}; :{}:'.format(indent, t)


def make_meta_string(metadata, indent):
    """Convert list of metadata lists into a string.

    Parameters:
        metadata (list): List of list pairs (key, value)
        indent (str): String used for indentation.

    Returns:
        str: Returns a metadata string suitable for a ledger-cli journal.

    >>> make_meta_string([['key1', 'value1'], ['key2', 'value2']], '  ')
    "  ; key1: value1\\n  ; key2: value2"
    """
    m = []
    for meta in metadata:
        m.append('{}; {}: {}'.format(indent, meta[0], meta[1]))

    return '\n'.join(m)


class Allocation(object):
    """Allocation class for transactions.

    Attributes:
        account (str): Name of the ledger account for this allocation.
        amount (float): Dollar value of the allocation.
        currency (str): String representing the allocation commodity.
            ``$``, ``USD``, ``CAN`` etc.
        assertion (bool): Set to `True` if allocation is a balance assertion.
            Allocation will be represented as:
            ::

            <account>                                      = <currency> <amount>

            Instead of:
            ::

            <account>                                        <currency> <amount>
        tags (list): Tag strings to add to the allocation.
        metadata (list): Key/value pairs to add to allocation.
    """

    def __init__(self, **kwargs):
        """Initialize allocation.

        Parameters:
            account (str): Name of the ledger account for this allocation.
            amount (float): Dollar value of the allocation.
            currency (str): String representing the allocation commodity.
            assertion (bool): Set to 'True' if allocation is balance assertion.
            tags (list): Tag strings to add to the allocation.
            metadata (list): Key/value pairs to add to allocation.
        """
        self.account = kwargs['account']
        self.amount = kwargs['amount']
        self.currency = kwargs.get('currency', '$')
        self.assertion = kwargs.get('assertion', False)
        self.tags = kwargs.get('tags', [])
        self.metadata = kwargs.get('metadata', [])

    def to_string(self, width=80, indent=4):
        """ Allocation as string. Fix to width in this.

        Keyword Args:
            width (int): White space added after allocation acount to align last
                digit of 'amount' to column `width`.
            indent (int): Number of spaces to indent each level of transaction.

        Return:
            str: Ledger-cli formatted string for the allocation.
        """

        ind = ' ' * indent
        acct = self.account
        if self.assertion:
            amt = '= {} {:.2f}'.format(self.currency, self.amount)
        else:
            amt = '{} {:.2f}'.format(self.currency, self.amount)

        # Calculate fill, split amount at decimal to align to decimal.
        fill = ' ' * (width - len(acct + amt.split('.')[0] + ind) - 3)

        outlist = []
        outlist.append(ind + acct + fill + amt)

{'fraction_non_alphanumeric': 0.11892726762145464, 'fraction_numerical': 0.005054759898904802, 'mean_word_length': 2.1756576014266606, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598195', 'n_tokens_mistral': 1980, 'n_tokens_neox': 1913, 'n_words': 680}