Skip to content

Instantly share code, notes, and snippets.

@etemiz
Last active November 16, 2023 02:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etemiz/dc366aad689febc2e85d57a5ac7f08c0 to your computer and use it in GitHub Desktop.
Save etemiz/dc366aad689febc2e85d57a5ac7f08c0 to your computer and use it in GitHub Desktop.
Read the strfry database using Python
import lmdb
lmdb_folder = '/path/to/strfry-db/'
lmdb_env = lmdb.open(lmdb_folder, max_dbs=10)
dbpl = lmdb_env.open_db(b'rasgueadb_defaultDb__EventPayload')
dbid = lmdb_env.open_db(b'rasgueadb_defaultDb__Event__id')
# read one event
with lmdb_env.begin(db=dbid) as txn:
with lmdb_env.begin(db=dbpl) as tpl:
event_id = bytes.fromhex('fff8923d6db9a6d116edf5a0f4b747ede05b282cc939ca41d1461e221d94e7b5')
cur = txn.cursor()
cur.set_range(event_id)
k, v = cur.item()
if k[:32] == event_id:
pl = tpl.get(v)
if pl:
ev = pl[1:].decode('utf-8')
print(ev)
else:
raise Exception("db corrupt!?")
else:
print('not found')
# read whole db
with lmdb_env.begin(db=dbid) as txn:
with lmdb_env.begin(db=dbpl) as tpl:
for key, value in txn.cursor():
pl = tpl.get(value)
if pl is None:
raise Exception("db corrupt!?")
key_hex = key.hex()[:64]
val = pl[1:].decode('utf-8')
print(key_hex, val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment