Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
There are a few ways to move data into and out of dh_weather.
- The default admin/content/dh_timeseries_weather.
- PHP code using entity_create or entity_load/entity_load_single + entity_save.
- RESTful web services (in Drupal 7 restws module, when this moves to D8 REST is in core).
Adding and Updating dh_timeseries_weather data programatically in PHP
// do a search using EntityFieldQuery
$fid = 13;
$varid = 125; // corresponds to an entry in the dh_variabledefinition table
$tstime = strtotime('2010-01-01');
$etype = 'node'; / type of entity to attach this weather data to
$precip = 1.5;
$temp = 38.0;
// find or create
$efq = new EntityFieldQuery;
$efq->entityCondition('entity_type', 'dh_timeseries_weather');
$efq->propertyCondition('entity_type', $etype);
$efq->propertyCondition('tstime', $tstime);
$efq->propertyCondition('featureid', $fid);
$rez = $efq->execute();
if (isset($rez['dh_timeseries_weather'])) {
$e = array_shift($rez[$etype]);
$tid = $e->tid;
$tsw = entity_load_single('dh_timeseries_weather', $tid);
} else {
// need to insert
$values = array(
'varid'=>$varid,
'featureid'=>$fid,
'entity_type'=>$etype,
'tstime' => $tstime
);
$tsw = entity_create('dh_timeseries_weather', $values);
}
// set properties
$tsw->temp = $temp;
$tsw->precip = $precip;
dpm($tsw,'weather object');
entity_save('dh_timeseries_weather', $tsw);
Adding and Updating dh_timeseries_weather data with REST
Using REST from R
Using REST from PHP
library(httr)
#Cross-site Request Forgery protection (Token needed for POST and PUT)
csrf <- GET(
url='http://myweather.org/restws/session/token/',
authenticate("restws_dude", "supersecret")
);
token <- content(csrf)
token
# search for Feature
feature <- GET(
"http://myweather.org/dh_timeseries_weather.json",
add_headers(X_CSRF_TOKEN = token),
query = list(
tstime = 1424926800,
featureid = 13
),
encode = "json",
verbose()
);
f <- content(feature );
Using REST from Python
Using Feeds Importer and Feeds Tamper
The experimental entity handler for Feeds importer provided access in commit f6aa61d in 7.x-2.x-dev of Feeds. Development of a custom Feeds Entity handler was required after this commit.