예제 #1
0
파일: qifacc.py 프로젝트: rodrigoieh/qifqif
def write_config(accounts, cfg_path, dry_run):
    """Update configuration file with extracted accounts names."""
    json_accs = {}
    for account in accounts:
        json_accs[account] = []
    json_accs.update(tags.load(cfg_path))
    if dry_run:
        print((tags.prettify(json_accs)))
    else:
        tags.save(cfg_path, json_accs)
    return json_accs
예제 #2
0
파일: __init__.py 프로젝트: flywire/qifqif
def main(argv=None):
    """Main function: Parse, process, print"""
    if argv is None:
        argv = sys.argv
    args = parse_args(argv)
    if not args:
        exit(1)
    original_tags = copy.deepcopy(tags.load(args['config']))
    with io.open(args['src'], 'r', encoding='utf-8', errors='ignore') as fin:
        lines = fin.readlines()
        transacs_orig = parse_file(lines, options=args)
    try:
        transacs = process_file(transacs_orig, options=args)
    except EOFError:  # exit on Ctrl + D: restore original tags
        tags.save(args['config'], original_tags)
        return 1
    res = dump_to_buffer(transacs + transacs_orig[len(transacs):])
    if not args.get('dry-run', False):
        with io.open(args['dest'], 'w', encoding='utf-8') as f:
            f.write(res)
    print(res)
    return 0 if len(transacs) == len(transacs_orig) else 1
예제 #3
0
def main(argv=None):
    """Main function: Parse, process, print"""
    if argv is None:
        argv = sys.argv
    args = parse_args(argv)
    if not args:
        exit(1)
    original_tags = copy.deepcopy(tags.load(args['config']))
    with io.open(args['src'], 'r', encoding='utf-8', errors='ignore') as fin:
        lines = fin.readlines()
        transacs_orig = parse_file(lines, options=args)
    try:
        transacs = process_file(transacs_orig, options=args)
    except EOFError:  # exit on Ctrl + D: restore original tags
        tags.save(args['config'], original_tags)
        return 1
    res = dump_to_buffer(transacs + transacs_orig[len(transacs):])
    if not args.get('dry-run', False):
        with io.open(args['dest'], 'w', encoding='utf-8') as f:
            f.write(res)
    print(res)
    return 0 if len(transacs) == len(transacs_orig) else 1
예제 #4
0
def main(argv=None):
    """Main function: Parse, process, print"""
    if argv is None:
        argv = sys.argv
    args = parse_args(argv)
    if not args:
        exit(1)
    original_tags = copy.deepcopy(tags.load(args["config"]))
    with io.open(args["src"], "r", encoding="utf-8", errors="ignore") as fin:
        lines = fin.readlines()
        transacs_orig = qifile.parse_lines(lines, options=args)
    try:
        transacs = process_transactions(transacs_orig, options=args)
    except EOFError:  # exit on Ctrl + D: restore original tags
        tags.save(args["config"], original_tags)
        return 1
    res = qifile.dump_to_buffer(transacs + transacs_orig[len(transacs) :])
    if not args.get("dry-run"):
        with io.open(args["dest"], "w", encoding="utf-8") as dest:
            dest.write(res)
    if args["batch"] or args["dry-run"]:
        print("\n" + res)
    return 0 if len(transacs) == len(transacs_orig) else 1