def main(): parser = get_opt_parser() opts = parser.parse_args() opts.model = get_model(opts.model) tw_opts = {"width": 50, "subsequent_indent": " ", "initial_indent": " "} wrapper = textwrap.TextWrapper(**tw_opts) records = [] for stream in opts.infile: print "## START %s" % (stream.name) if opts.collate and opts.data == "pump": page = HistoryPage(bytearray(stream.read()), opts.model) records.extend(page.decode(larger=opts.larger)) elif opts.data == "glucose": page = Response(data=bytearray(stream.read())) records.extend(opts.model.iter_glucose_pages.Cursor(opts.model).find_records(page)) else: records = find_records(stream, opts) i = 0 for record in records: prefix = "#### RECORD {} {}".format(i, str(record)) if getattr(record, "pformat", None): print record.pformat(prefix) else: # json.dumps(record, indent=2) print prefix i += 1 print "`end %s: %s records`" % (stream.name, len(records)) stream.close() if opts.collate: opts.out.write(json.dumps(records, indent=2))
def main( ): parser = get_opt_parser( ) opts = parser.parse_args( ) tw_opts = { 'width': 50, 'subsequent_indent': ' ', 'initial_indent': ' ', } wrapper = textwrap.TextWrapper(**tw_opts) for stream in opts.infile: print "## START %s" % (stream.name) records = [ ] if opts.collate: page = HistoryPage(bytearray(stream.read( ))) records.extend(page.decode(larger=opts.larger )) else: records = find_records(stream, opts) i = 0 for record in records: prefix = '#### RECORD {} {}'.format(i, str(record)) if getattr(record, 'pformat', None): print record.pformat(prefix) else: json.dumps(record, indent=2) i += 1 print "`end %s: %s records`" % (stream.name, len(records)) if opts.collate: opts.out.write(json.dumps(records, indent=2)) stream.close( )
def main(): parser = get_opt_parser() opts = parser.parse_args() tw_opts = { 'width': 50, 'subsequent_indent': ' ', 'initial_indent': ' ', } wrapper = textwrap.TextWrapper(**tw_opts) records = [] for stream in opts.infile: print "## START %s" % (stream.name) if opts.collate: page = HistoryPage(bytearray(stream.read())) records.extend(page.decode(larger=opts.larger)) else: records = find_records(stream, opts) i = 0 for record in records: prefix = '#### RECORD {} {}'.format(i, str(record)) if getattr(record, 'pformat', None): print record.pformat(prefix) else: json.dumps(record, indent=2) i += 1 print "`end %s: %s records`" % (stream.name, len(records)) stream.close() if opts.collate: opts.out.write(json.dumps(records, indent=2))
def find_records (self, page, larger=None): decoder = HistoryPage(page, self.pump.model) records = decoder.decode( ) print "SINCE", self.since.isoformat( ) for record in records: print " * found record", record['_type'], record.get('timestamp') print " * should quit", record.get('timestamp') < self.since.isoformat( ), self.enough_history if record.get('timestamp'): dt = parse(record['timestamp']) dt = dt.replace(tzinfo=self.timezone) record.update(timestamp=dt.isoformat( )) if record['timestamp'] < self.since.isoformat( ): self.enough_history = True if record['timestamp'] >= self.since.isoformat( ): self.records.append(record) return records
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 "```"
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 "```"
def download_history (self, args, nrPages): records = [ ] for i in range(1, nrPages): print "Next page ", i try: pageRaw = self.download_page(i) pageResult = HistoryPage(pageRaw.data, self.pump.model) records.extend(pageResult.decode()) except: print "Unexpected error when downloading cgm-page ", i, " from pump:", sys.exc_info()[0] recordsJson = json.dumps(records); args.parsed_data.write(recordsJson) handle = open('history.json', 'wb') handle.write(recordsJson) handle.close( )
def download_history(self, args, nrPages): records = [] for i in range(1, nrPages): print "Next page ", i try: pageRaw = self.download_page(i) pageResult = HistoryPage(pageRaw.data, self.pump.model) records.extend(pageResult.decode()) except: print "Unexpected error when downloading cgm-page ", i, " from pump:", sys.exc_info( )[0] recordsJson = json.dumps(records) args.parsed_data.write(recordsJson) handle = open('history.json', 'wb') handle.write(recordsJson) handle.close()