Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python api do not implement an --rejected option as in dbadb import #258

Open
pat1 opened this issue May 9, 2021 · 1 comment
Open

Python api do not implement an --rejected option as in dbadb import #258

pat1 opened this issue May 9, 2021 · 1 comment
Assignees
Labels

Comments

@pat1
Copy link
Contributor

pat1 commented May 9, 2021

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?

@spanezz
Copy link
Contributor

spanezz commented Nov 23, 2021

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

@spanezz spanezz assigned pat1 and unassigned spanezz Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants