I understand that a new activity can be added to a database via
a = db.new_activity(
code="A",
name="New activity"
)
a.save()
I can add an exchange to the newly created activity via
a.new_exchange(
amount=1,
input=db.random(),
type="technosphere",
).save()
However, the newly created activity will not "create" a product. How do I assign an existing or new reference product to a new activity?
db = bd.Database('someDataBase')
db.new_node(code="code", name="name", unit="kilogram", location="CN").save()
# this should do it but your ref product will be set to None
# if you want that
act = db.get('code')
act['reference product'] = 'whatever'
act.save()
# now if you add a production exchange it will also keep the ref product
act.new_edge(input=act, amount=1, type='production')
There is probably a better way to do it, this works for me.