-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmm-pages.py
executable file
·90 lines (77 loc) · 2.37 KB
/
mm-pages.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
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# PYTHON_ARGCOMPLETE_OK
from decocare import commands
import io
import json
from datetime import datetime
from dateutil import relativedelta
from decocare import lib
from decocare.history import parse_record, HistoryPage
from decocare.helpers import cli
def page_range (spec):
r = spec.split(',')
pages = [ ]
for s in r:
p = s.split('..')
if len(p) is 2:
pages.extend(range(int(p[0]), int(p[1]) + 1))
continue
p = s.split('-')
if len(p) is 2:
pages.extend(range(int(p[0]), int(p[1]) + 1))
continue
pages.append(int(s))
return pages
class PumpPager (cli.CommandApp):
"""%(prog)s - Download and decode pages of history from pump.
Download history pages from the pump.
"""
def customize_parser (self, parser):
parser.add_argument('--query',
dest="query",
action="store_true",
default=False,
help="Query number of pages available."
)
# subparsers = parser.add_subparsers(help="Type of pages", dest="command")
# history_parser = subparsers.add_parser("history", help="ReadHistoryData pages")
# history_parser.add_argument('pages'
# )
choices = [ 'history', 'cgm', 'vcntr' ]
parser.add_argument('variant',
# action="append",
choices=choices,
help="Type of history pages to retrieve."
)
parser.add_argument('range',
help="Page range",
nargs='+',
type=page_range
)
return parser
def download_page (self, number):
kwds = dict(page=number)
page = self.exec_request(self.pump, commands.ReadHistoryData, args=kwds)
return page
def query_pages (self):
pages = self.exec_request(self.pump, commands.ReadCurPageNumber)
return pages.getData( )
def main (self, args):
print args
print args.variant
print args.range[0]
if args.query:
self.query_pages( )
pages = args.range[0]
larger = int(self.pump.model.getData( )[1:]) > 22
records = [ ]
for n in pages:
history = self.download_page(n)
page = HistoryPage(history.data)
records.extend(page.decode( ))
print "```json"
print json.dumps(records, indent=2)
print "```"
if __name__ == '__main__':
app = PumpPager( )
app.run(None)