-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (61 loc) · 1.69 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import glob
import sys
import click
import Levenshtein
import importer
import block
def match(query, pool):
query = query.lower()
best_score = -1
best_block = None
for block in pool:
score = Levenshtein.ratio(query, block.summary.lower())
if score > best_score:
best_block = block
best_score = score
return best_block, best_score
def test(import_file):
ldg_files = glob.glob("*.ldg")
corpus = []
for file_ in ldg_files:
with open(file_) as f:
corpus.extend(block.parse(f))
for query in importer.import_csv(import_file):
ablock, score = match(query.summary, corpus)
print query.date, query.summary
print ablock, score
print
@click.group()
def cli():
pass
@cli.command()
@click.argument('target', type=click.File('r'), default='-')
def format(target):
blocks = block.parse(target)
for b in blocks:
b.write(sys.stdout)
@cli.command()
@click.argument('target', type=click.File('r'), default='-')
def clear(target):
blocks = block.parse(target)
for b in blocks:
if b.is_transaction():
b.cleared = '*'
b.write(sys.stdout)
@cli.command()
@click.argument('target', type=click.File('r'))
def format(target):
for t in block.parse(target):
t.write(sys.stdout)
@cli.command(name="import")
@click.argument('import_file', type=click.File('r'), default='-')
@click.option('--target')
def import_(import_file, target):
test(import_file)
@cli.command()
@click.argument('archive')
@click.argument('input', type=click.File('r'), default='-')
def save(archive, input):
importer.save(archive, input)
if __name__ == "__main__":
cli()