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

Serialization of EXIF data for mongodb, JSON etc. #110

Open
jtlz2 opened this issue Mar 26, 2020 · 4 comments
Open

Serialization of EXIF data for mongodb, JSON etc. #110

jtlz2 opened this issue Mar 26, 2020 · 4 comments

Comments

@jtlz2
Copy link

jtlz2 commented Mar 26, 2020

I need to be able to serialize the tags dictionary into a format ingestible by mongodb e.g. JSON. Right now all the tags are of <type 'instance'> though.

PIL's image._getexif() does this - while also preserving types such as float, int, bool etc.

Are you able to assist?

Excellent package of course - for which many thanks.

@maxlaverse
Copy link

Is this a duplicate of #59 ?

@ianare
Copy link
Owner

ianare commented Jul 31, 2020

I had actually started work on this a while ago, the main problem is not breaking backwards compatibility. The code is a bit hairy on this. You could do a split on the first space in the tag dict...

@tenuki
Copy link

tenuki commented Dec 20, 2020

I had actually started work on this a while ago, the main problem is not breaking backwards compatibility. The code is a bit hairy on this. You could do a split on the first space in the tag dict...

Problem isn't the keys but the values, as they are instances and pymongo doesn't know how to handle them.

In my case I do:

            tags = exifread.process_file(f)
            tags = {k:str(v).strip()  for k, v in tags.items()}

to convert output in a new dictionary. I would have submitted a patch with this if the library returned a class where to add this.

I would make sense to create and return the class hdr and that anyone can call tags() or perhaps a new json() method whenever it be needed.

Also, in that chase, I would also replace k for k.replace(' ', '.') in my code above.

@tenuki
Copy link

tenuki commented Dec 20, 2020

Of course, as it is commented on #59, it would be better if you can avoid to str(v) and keep value's type in json()'s output..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants