include "Modules/feed/feed_model.php"; $feedclass = new Feed($mysqli, $redis, $timestore_adminkey); // local userid $userid = 1; // 1) Fetch remote server feeds $server = "http://192.168.1.69/emoncms"; $apikey = "enter your apikey here"; $feeds = file_get_contents($server . "/feed/list.json?apikey={$apikey}"); $feeds = json_decode($feeds); // 2) For each feed on the remote foreach ($feeds as $feed) { if ($feed->datatype == 1 && $feed->engine == 1) { import_timestore($mysqli, $userid, $server, $apikey, $feed); } if ($feed->engine == 0) { import_mysql($mysqli, $userid, $server, $apikey, $feed); } //echo " Downloading: ".$feed->id." ".$feed->name."\n"; } function import_timestore($mysqli, $userid, $server, $apikey, $feed) { // We start by checking if there is a local feed that has the same name as the remote feed // Decided against this - best to use same feedid's as target //$result = $mysqli->query("SELECT id FROM feeds WHERE `name` = '".$feed->name."' AND `userid` = '$userid'"); //$row = $result->fetch_array(); //$feedid = $row['id']; $result = $mysqli->query("SELECT id FROM feeds WHERE `id` = '" . $feed->id . "'"); if (!$result->num_rows) { // Create feed echo "create feed " . $feed->id . "\n"; $result = $mysqli->query("INSERT INTO feeds (id,userid,name,tag,datatype,public,engine) VALUES ('" . $feed->id . "','{$userid}','" . $feed->name . "','" . $feed->tag . "','" . $feed->datatype . "','false','1')");
// Fetch remote server feed list $feeds = file_get_contents($remote_server . "/feed/list.json?apikey={$remote_apikey}"); $feeds = json_decode($feeds); $number_of_feeds = count($feeds); echo $number_of_feeds . " Emoncms.org feeds found\n"; if ($number_of_feeds == 0) { echo "No feeds found at remote account\n"; die; } foreach ($feeds as $feed) { $feed->userid = $local_emoncms_userid; if ($link_to_local_emoncms) { register_emoncms_feed($mysqli, $redis, $feed); } if ($feed->engine == 0 && $mysqli) { import_mysql($feed, $remote_server, $remote_apikey, $mysqli); } if ($feed->engine == 1 && $feed->datatype == 1) { import_phptimestore($feed->id, $remote_server, $remote_apikey, $engines['phptimestore']['datadir']); } if ($feed->engine == 2) { import_phptimeseries($feed->id, $remote_server, $remote_apikey, $engines['phptimeseries']['datadir']); } if ($feed->engine == 5) { import_phpfina($feed->id, $remote_server, $remote_apikey, $engines['phpfina']['datadir']); } if ($feed->engine == 6) { import_phpfiwa($feed->id, $remote_server, $remote_apikey, $engines['phpfiwa']['datadir']); } if ($feed->engine == 4 && $feed->datatype == 1) { import_phptimestore($feed->id, $remote_server, $remote_apikey, $engines['phptimestore']['datadir']);