Example farmOS.py CSV import script

Hmmm… I think this means there is a syntax error somewhere before line #37. An un-closed string could cause this issue - is it possible you modified one of the lines/variables above that (like the hostname or username) and have extra and/or missing parenthesis? The original file runs OK for me.

So this just depends how you design your import script! You could design the script to be hard coded for a specific asset type, read the asset type from a column (like the current 2.x CSV export has), or even take the asset type as an argument to the script.

The import_plantings.py example is quite simple - it only reads a few columns from the CSV file and the asset type is hard coded to be plant: farmOS.py 2.x Import example · GitHub

Not with this example script - but with a script it would be possible, yes! That said, I think that ideally the use case you are describing could be covered with the core farmOS CSV importers UI - we are working on this here: https://www.drupal.org/project/farm/issues/3151244

But it also seems like it could be useful to provide some farmOS.py/farmOS.js import scripts that would be compatible with the format of the current CSV exports. This script could do what you are describing, update existing OR create new. Although I think the utility of such a script wouldn’t match the fully functioning CSV importer we are building.

Just to be clear - I imagine you’ll need to create custom script(s) for importing these. The CSV importer UI would likely work for a subset of the fields you are importing but the more complicated pieces might require a script (things like quantities, entity references, special logic, etc). A hybrid approach might work too! It really depends on the format of your worksheets and what all you are trying to do. I think it would be worthwhile for you to work on a custom script right now.

Maybe you could open a new thread for specific questions regarding these worksheets? An example would help too!

2 Likes