<commit_before>#!/usr/bin/env python
# coding: utf-8

import re

import aib, cfg, ofx

def main():
    cleanup_re = re.compile('[- 	]+')
    config = cfg.config()
    formatter = ofx.ofx()

    for user in config.users():
        creds = config[user]
        bank = aib.aib(creds)
        bank.login()
        bank.scrape()
        bank.bye()

        for account in bank.getdata().values():
            name = re.sub(cleanup_re,
                          '_',
                          account['accountId']).lower()
            f = open('/tmp/%s_%s.ofx' % (user, name),
                     'w')
            f.write(formatter.prettyprint(account))
            f.close

if __name__ == '__main__':
    main()
<commit_msg>Runner script is now more readable and sensible.<commit_after>#!/usr/bin/env python
# coding: utf-8

import optparse, re

import aib, cfg, ofx


def getOptions():
    parser = optparse.OptionParser()
    option_list = [
        optparse.make_option(
            '-d', '--output-dir',
            dest='output_dir', help='directory to put OFX files in [/tmp]'
        ),
    ]
    parser.add_options(option_list)
    parser.set_defaults(output_dir='/tmp')
    return parser.parse_args()


def getData(user, config, output_dir, formatter):
    cleanup_re = re.compile('[- 	]+')

    # Login to the bank, scrape data for all accounts.
    creds = config[user]
    bank = aib.aib(creds)
    bank.login()
    bank.scrape()
    bank.bye()

    # Save each account to separate OFX file.
    for account in bank.getdata().values():
        name = re.sub(cleanup_re,
                      '_',
                      account['accountId']).lower()
        f = open(
            '%s/%s_%s.ofx' % (output_dir, user, name),
            'w'
        )
        f.write(formatter.prettyprint(account))
        f.close


def main():
    # Parse command line options.
    (options, args) = getOptions()

    # Read user-provided credentials.
    config = cfg.config()
    formatter = ofx.ofx()

    # Iterate through accounts, scrape, format and save data.
    for user in config.users():
        getData(user, config, options.output_dir, formatter)


if __name__ == '__main__':
    main()

{'fraction_non_alphanumeric': 0.13515981735159818, 'fraction_numerical': 0.0009132420091324201, 'mean_word_length': 2.013755158184319, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4966105', 'n_tokens_mistral': 711, 'n_tokens_neox': 683, 'n_words': 167}