Skip to content

Instantly share code, notes, and snippets.

View paul121's full-sized avatar

Paul Weidner paul121

View GitHub Profile
@paul121
paul121 / 1.txt
Last active August 4, 2016 18:15
Paul Atom Settings
asdfasfd
@paul121
paul121 / docker-compose.yml
Last active September 8, 2019 19:31
docker-compose.yml for bare D7 install
version: '3.1'
services:
drupal:
image: drupal:7.67-apache
ports:
- 80:80
- 443:443
volumes:
@paul121
paul121 / log_gen.py
Created November 5, 2019 19:23
Generate random egg harvest values for a date range
from datetime import date, timedelta
import random
import logging
from farmOS import farmOS
f = farmOS('tilth2019.farmos.net', 'paul', 'password')
log_name = 'Egg Collection'
log_type = 'farm_harvest'
@paul121
paul121 / log_loop.py
Created November 13, 2019 02:19
Looping through log results
farm = farmOS(hostname=hostname, username=username, password=password)
test_log_done = {'name':'This is log is done', 'type':'farm_observation','done': 1}
test_log_not_done = {'name':'This is log is NOT done', 'type':'farm_observation', 'done': 0}
farm.log.send(test_log_done)
farm.log.send(test_log_not_done)
all_logs = farm.log.get()
for log in all_logs['list']:
@paul121
paul121 / server-info-flow.json
Created November 27, 2019 09:19
node-red test flow
[
{
"id": "58ff452f.d398fc",
"type": "tab",
"label": "Test farmOS Flow",
"disabled": false,
"info": ""
},
{
"id": "4e4527de.360678",
@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
@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 / 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 / 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"