# !pip install farmOS==1.0.0b3
from farmOS import farmOS
hostname="http://localhost"
client = farmOS(hostname, client_id="farm", scope="farm_manager")
current_token = client.authorize()| // Import client factory method for node. | |
| const {client} = require('farmos/dist/cjs/farmOS'); | |
| // Create a custom auth method to set the api-key header and farm_id query param. | |
| const apiKeyAuth = (request, authOpts = {}) => { | |
| request.interceptors.request.use( | |
| config => { | |
| return { | |
| ...config, | |
| headers: { |
| import os | |
| from requests.sessions import Session | |
| from farmOS.client_2 import ResourceBase | |
| # Allow testing via http. | |
| os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" | |
| class AggregatorSession(Session): |
Install farmOS.py using pip. Rather
than installing system wide, it is recommended to install packages into a
virtual environment. For more information see Installing Python Packages.
# Dedicate a directory for farmOS scripts.
cd farmos_scripts| # Library definitions prefixed with Drupal module name | |
| # Some kind of a ol-federated provided entrypoint? All OL chunks depend on this? | |
| farm_map/ol_federated_entrypoint: { .. } | |
| # Many ol_* chunks each provided as a library. | |
| farm_map/ol_core: { .. } # Ideally we can create a single chunk with all of the essential OL chunks needed for farmOS-map. | |
| farm_map/ol_control_*: { .. } # Optional controls | |
| farm_map/ol_interaction_*: { .. } # Optional interactions | |
| farm_map/ol_source_*: { .. } # Optional sources eg: Tile, Vector, WMS, XYZ... some included in ol_core? |
| { | |
| "header" : { | |
| "app":"RPG Map 2", | |
| "appVersion":16.2, | |
| "appAuthor":"Sebastien Benard", | |
| "fileType":"JSON Map", | |
| "fileVersion":10, | |
| "url":"https://deepnight.net/tools/rpg-map/" | |
| }, | |
| "version":10, |
| """Move farm info to separate table. | |
| Revision ID: cbc5e5092520 | |
| Revises: d2422b5a6859 | |
| Create Date: 2020-06-02 23:36:50.018420 | |
| """ | |
| from alembic import op | |
| import sqlalchemy as sa | |
| from sqlalchemy.dialects import postgresql |
Just realized I'm doing something similar for the CSV Importer. I found myself querying for a taxonomy term by the term'sname multiple times. This required me to also look up the taxonomy_vocabulary vid multiple times... but rather than querying the farmOS server for the taxonomy vid each time, I maintain a copy of the resources from /farm.json. This makes it easy to get a taxonomy vocabulary vid from the vocabularyname without a request to the server.
With the vid, I then make a request for any term that matches the vocabulary name and term name.
Some preliminary helper code that handles getting a taxonomy term from a name specified in a CSV file:
def _get_farmos_taxonomy_term(self, name, taxonomy_name, create=False):
taxonomy_vid = self.farm_client_info.get('resources').get('taxonomy_term').get(taxonomy_name).get('vid')
taxonomy_vid = int(taxonomy_vid)