i had to write a similar program when i was importing a lot
of transactions, but it effectively worked in the opposite
direction of what you require so it isn't very useful (i was
scanning a list of my own making to turn it into beancount
transactions). i wrote it in Python. it takes csv format
input.
to adapt it to your purposes you'd need a way to dump the
transactions to a csv format, but from those you could run my
code and that would give you a python list that you could
then list the lots in whatever format you'd like.
alas, i'm short on time right now until Monday or Tuesday
but if you want to explore this send me an e-mail and we
can go from there.
fin