hannob / vacdec

Python script to decode the EU Covid-19 vaccine certificate
The Unlicense
242 stars 89 forks source link

Print only some data #10

Closed HackeCode closed 3 years ago

HackeCode commented 3 years ago

Hi, there is a way to print only some data of the decoded qr? like only the name or date of birth?

jugmac00 commented 3 years ago

Yes, that is possible, but you need to modify the source code.

The following line https://github.com/hannob/vacdec/blob/65b290a4ea400385fcdc6d0533dcbb94b9cd8203/vacdec#L23 prints a the complete data structure, which is a nested dictionary.

If you only want to access a specific value, you need to drill down.

E.g. the the "day of birth" would be (for the bar code I have access to):

pprint.pprint(cbor2.loads(decoded.value[2])[-260][1]["dob"])

I suggest that you set a breakpoint just before the last line, and play with the result a bit.

If you have never used a debugger before - I gave a 5 min lightning talk at PythonIreland a while ago: https://www.youtube.com/watch?v=Fxkco-gS4S8

If you wanted to access different pieces of data via command line, it would be necessary to rewrite the script to take arguments (which I think is outside of the scope of this project here).

hannob commented 3 years ago

I don't plan to make this script more complicated and add parameters and stuff. Ultimately it just ends with a python structure that contains all the info and gets prettyprinted out. But as @jugmac00 pointed out it isn't hard to adapt to print out specific values.