dballe
dballe copied to clipboard
Python api do not implement an --rejected option as in dbadb import
in:
with db.transaction() as tr:
with importer.from_file(totalbodyfile) as f:
tr.import_messages(f,overwrite=True, update_station=True,import_attributes=True)
I cannot use --rejected option as in "dbadb import". Is the same to develop
for message in f:
try:
tr.import_messages(message,overwrite=True, update_station=True,import_attributes=True)
except:
print ("rejected")
for perfomance too?
Would something like this work?
importer = dballe.Importer("BUFR")
exporter = dballe.Exporter("BUFR")
with open("rejected.bufr", "wb") as out:
with db.transaction() as tr:
with dballe.File(pathname) as f:
for binmsg in f:
for msg in importer.from_binary(binmsg):
try:
tr.import_messages(msg)
except Exception as e:
print("Error importing message:", e)
binmsg = exporter.to_binary(msg)
out.write(binmsg)
If it can help, I just added examples to the documentation of various ways to import messages