I hope this example can help serve as a starting point for other custom CSV importers using Python + farmOS.py. Code + installation and usage instructions are here: farmOS.py 2.x Import example · GitHub
This example reads a
date from a CSV and creates a Plant asset with a seeding log on the specified
date. The Plant asset’s
plant_type is either loaded from an existing term, or a new
plant_type will be created with a reference to the
crop_family term (which is also created if one does not already exist). I think this incorporates both simple and more complicated concepts that will be run into when creating custom importers with Python:
- Command line arguments
- CSV file loading + parsing
- Date parsing
- Client instantiation + authorization
- Create an asset with a plant_type/taxonomy term relationship
- Create a log with asset relationship
- Request existing entity with query filters (example is of taxonomy terms filtered by name)
While farmOS does have CSV importers, they require a strict format and are limited in what fields are supported. Even a fairly simple script allows for many more options: flexibility with the CSV format, the ability to create additional fields, multiple entities + entity relationships (assets + logs referencing assets), conditional logic, etc… but they also require customization & some programming knowledge!
Happy to answer any questions & would love to hear ideas for improvements!