-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·85 lines (66 loc) · 2.13 KB
/
main.py
File metadata and controls
executable file
·85 lines (66 loc) · 2.13 KB
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
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
# coding: utf-8
"""
Read Employee data to return turnover information.
This is a example Python program to read and process XML files.
"""
from employees.employees import Employees
import argparse
import logging
import os.path
import sys
def main(argv=sys.argv):
""" Test employees class. """
__version__ = '0.3.0'
parser = argparse.ArgumentParser(
prog=os.path.basename(argv[0]),
usage='%(prog)s [options]',
description='a Python example program to show XML processing',
epilog='© 2013-2018 Frank H Jung mailto:frankhjung@linux.com')
parser.add_argument(
'infile',
nargs='?',
type=argparse.FileType('r'),
default='data/test.xml',
help='alternate XML file to test')
parser.add_argument(
'-v',
'--verbose',
help='verbose output',
action='count')
parser.add_argument(
'--version',
action='version',
version=__version__)
# process command line arguments
args = parser.parse_args()
prog = parser.prog
infile = args.infile
verbose = args.verbose
# show command parameters
logging.basicConfig(format="%(asctime)s %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
if verbose:
logger.setLevel(logging.DEBUG)
# load employees from XML
e = Employees(infile)
logger.debug("infile ......................: {}".format(infile.name))
logger.debug("prog ........................: {}".format(prog))
logger.debug("verbose .....................: {}".format(verbose))
logger.debug("dump ........................: \n{}".format(e.dump()))
t = e.getById('003')
logger.debug("total for id 3 ..............: {}".format(t))
t = e.getByName('frank')
logger.debug("total for frank .............: ${:,}".format(t))
t = e.getTotalByYear(2012)
logger.debug("turnover for 2012 ...........: ${:,}".format(t))
t = e.getByYear('frank', 2012)
logger.debug("turnover for frank in 2012 ..: {}".format(t))
return 0
#
# MAIN
#
if __name__ == '__main__':
rc = main(sys.argv)
sys.exit(rc)
# EOF