-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
executable file
·60 lines (49 loc) · 1.72 KB
/
calculator.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
#! /usr/bin/env python
import sys
from optparse import OptionParser, make_option
from bank import *
def main():
def checkRequiredArguments(options, parser):
error_arguments = []
if options.type is None:
error_arguments.append('Type must be specified.')
if options.bank is None:
error_arguments.append('Bank name must be specified.')
if options.file is None:
error_arguments.append('File must be specified.')
if error_arguments:
parser.error(
'Missing REQUIRED parameters: ' + str(error_arguments)
)
option_list = [
make_option(
"-f", "--file", type="string", dest="file",
help=("xls file with alla transactions from the bank")
),
make_option(
"-b", "--bank", type="choice", dest="bank",
choices=['ABN', ], help=("Bank name to choose from")
),
make_option(
"-t", "--type", type="choice", dest="type", default=1,
choices=['0', '1'], help=(
"type of calculation. it should be 1 for "
"income or 0 for expenses"
)
),
make_option(
"-p", "--pattern", type="string", dest="pattern",
help="pattern to search in the description of every transaction"
),
]
parser = OptionParser(
"usage: %prog [options])",
option_list=option_list,
version="%prog 0.1"
)
(options, args) = parser.parse_args()
checkRequiredArguments(options, parser)
bank = globals()[options.bank](options.file)
bank.get_amount(int(options.type), options.pattern)
if __name__ == '__main__':
sys.exit(main())