Skip to content

Instantly share code, notes, and snippets.

View paul121's full-sized avatar

Paul Weidner paul121

View GitHub Profile
@paul121
paul121 / farmos_image_gps_observation.py
Created May 3, 2020 20:09
Create a farmOS Observation log with Timestamp and Geometry from a JPEG image.
import base64
from datetime import datetime
from farmOS import farmOS
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
hostname = "http://localhost"
username = "username"
password = "password"
@paul121
paul121 / caching_description.md
Last active May 5, 2020 02:32
farmOS client caching

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)
@paul121
paul121 / farmos_aggregator_farm_info_migration.py
Created June 3, 2020 15:21
Alembic migration that moves data from one column to another table.
"""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
@paul121
paul121 / demo.geojson
Created June 4, 2020 20:27
farmOS Map Style Function Demo
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"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,
@paul121
paul121 / libraries.yml
Last active May 18, 2021 22:34
OL-federated Drupal library example
# 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?
@paul121
paul121 / README.md
Last active July 26, 2021 17:17
farmOS.py 2.x Import example

Instructions

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
@paul121
paul121 / aggregator_test.py
Last active January 5, 2022 20:39
farmOS.py aggregator preliminary
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):
@paul121
paul121 / aggregator_js_test.js
Last active February 8, 2022 01:01
Example node script for making aggregator requests via farmOS.js
// 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: {
@paul121
paul121 / jupyterlite_farmospy.ipynb
Last active February 10, 2022 07:29
Example using the farmOS.py classes in jupyterlite.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.