json shortcut

7 views
Skip to first unread message

Mario Frasca

unread,
Aug 5, 2018, 9:44:15 PM8/5/18
to ghini/bauble
this is mostly a note to my forgetful self, hopefully to advantage of others too.

brief version:

print '\n'.join(['''{"object": "accession", "code": "%(ref)s", "species": "%(species)s"},\n{"object": "plant", "accession": "%(ref)s", "code": "1", "quantity": 1, "location": "A1"},\n{"object": "plant_note", "plant": "%(ref)s.1", "category": "<coords>", "note": "lat: %(lat)f, lon: %(lon)f"},''' % i for i in k])

longish version:

imagine you have a list of dictionaries, and that these dictionaries identify plants, with species, accession code, coordinates, …, what else? no, and nothing else really.  we assume a location, or you can replace the hard coded A1 with whatever location field in your dictionaries.  we assume quantity 1.

anyhow, the above would print a fragment of a json file you can import.  your notes should be timestamped somehow, and you first need to make sure that you have all your species in place.  that is left as an exercise to the interested reader.

best, everybody,
Mario
Reply all
Reply to author
Forward
0 new messages