def copyRow(self, row): rowId = row['id'] blob = row['lppa'] appList = [] try: lppa = msgpack.unpackb(blob) appList = [AppInfo.from_v1(k, v) for k, v in lppa.items()] except msgpack.exceptions.UnpackException: pass return if len(appList) <= 0: try: b = lzma.decompress(blob) lppa = simplejson.loads(b) appList = [AppInfo(**item) for item in lppa] except lzma.LZMAError: pass if len(appList) <= 0: logger.warning('not a valid lppa row {}'.format(rowId)) return lppas = [x.value_v2() for x in appList] # pprint.pprint(lppas) logger.debug('copying {}'.format(rowId)) blob = row['lppa'] o = { 'v': 3, 'data': lppas, } s = simplejson.dumps(o, separators=[':', ','], ensure_ascii=True) b = s.encode('ascii') blob = zlib.compress(b, 1) sql = """INSERT INTO did_lppa_v3 (id, did, lppa) VALUES (:rowId, :did, :blob) ON DUPLICATE KEY UPDATE id = id""" p = { 'blob': blob, 'rowId': row['id'], 'did': row['did'], } db.session.execute(sql, p) logger.debug('copied {}'.format(rowId))
def copyRow(self, row): rowId = row['id'] blob = row['lppa'] appList = [] try: lppa = msgpack.unpackb(blob) appList = [AppInfo.from_v1(k, v) for k, v in lppa.items()] except msgpack.exceptions.UnpackException: pass if len(appList) <= 0: try: b = lzma.decompress(blob) lppa = simplejson.loads(b) appList = [AppInfo(**item) for item in lppa] except lzma.LZMAError: pass if len(appList) <= 0: logger.warning('not a valid lppa row {}'.format(rowId)) return logger.debug(rowId) lppas = [x.value_v2() for x in appList] # pprint.pprint(lppas) logger.debug('copying {}'.format(rowId)) blob = row['lppa'] o = { 'v': 3, 'data': lppas, } s = simplejson.dumps(o, separators=[':', ','], ensure_ascii=True) b = s.encode('ascii') blob = zlib.compress(b, 1)
}, } }) sql = """SELECT * FROM dsid_lppa_v2 WHERE id = 3249444""" row = db.session.execute(sql).fetchone() blob = row['lppa'] _ = msgpack.unpackb(blob) pprint.pprint(_) appList = [] try: lppa = msgpack.unpackb(blob) appList = [AppInfo.from_v1(k, v) for k, v in lppa.items()] except msgpack.exceptions.UnpackException: pass pprint.pprint(appList) # # if len(appList) <= 0: # try: # b = lzma.decompress(blob) # lppa = simplejson.loads(b) # appList = [AppInfo(**item) for item in lppa] # except lzma.LZMAError: # pass # pprint.pprint(appList)