Skip to content

Instantly share code, notes, and snippets.

View paul121's full-sized avatar

Paul Weidner paul121

View GitHub Profile
@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 / 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?
{
"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 / 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.
@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 / 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_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 / module.js
Last active February 4, 2020 22:43
Field Module template files (DRAFT)
// This file should be in a ~/dist directory (can't show directories in gists)
// Field Module Code here
@paul121
paul121 / restws_oauth2_server.module
Created January 14, 2020 18:28
OAuth Path Scope Check
/**
* Implements hook_init().
*
* Performs a user login from the User ID of the Authentication Token.
*/
function restws_oauth2_server_init() {
// Load the OAuth2 Server and Scope that are to be authenticated against.
$server_name = variable_get('restws_oauth2_server_name', FALSE);
$scope_name = variable_get('restws_oauth2_server_scope', FALSE);
@paul121
paul121 / aggregator_tracker.py
Last active January 2, 2020 08:00
Aggregator Tracker Brainstorm
from farmosaggregator import Tracker
# Define a tracker that inherits from the Aggregator Tracker base class
class SpinachStudy(Tracker):
def __init__(self):
self.name = "Spinach Study Tracker"
self.description = "Aggregate spinach plantings and field data for analysis."
def get_farm_data(self, farmos_client):
# this list represents one farm's data for the study