<?php require_once 'cartodb.class.php'; require_once 'config.php'; date_default_timezone_set($timezone); $url = $instagram['api'] . $instagram['endpoint'] . '?access_token=' . $instagram['token']; // Load images $jsonString = file_get_contents($url); $jsonArr = json_decode($jsonString, true); $images = $jsonArr['data']; $cartodb = new CartoDBClient($cartodb_config); if (!$cartodb->authorized) { error_log("uauth"); print 'There is a problem authenticating, check the key and secret.'; exit; } // Find max timestamp $response = $cartodb->runSql("SELECT MAX(timestamp) FROM instagram"); $max = array_pop($response['return']['rows'])->max; foreach ($images as $image) { if ($image['created_time'] > $max && isset($image['location'])) { $location = $image['location']; $latitude = $location['latitude']; $longitude = $location['longitude']; $place_name = isset($location['name']) ? $location['name'] : ''; $caption = isset($image['caption']['text']) ? $image['caption']['text'] : ''; $image_thumb = $image['images']['thumbnail']['url']; $image_low = $image['images']['low_resolution']['url']; $image_standard = $image['images']['standard_resolution']['url']; if (isset($image['videos'])) { $video_low = $image['videos']['low_resolution']['url'];
<?php mb_internal_encoding("UTF-8"); mb_http_output("UTF-8"); require_once 'cartodb.class.php'; require_once 'config.php'; $cartodb = new CartoDBClient($cartodb_config); if (!$cartodb->authorized) { error_log("uauth"); print 'There is a problem authenticating, check the key and secret.'; exit; } $response = $cartodb->runSql("SELECT cartodb_id, latitude, longitude FROM spot WHERE altitude IS NULL ORDER BY timestamp DESC LIMIT 10"); foreach ($response['return']['rows'] as $row) { $cartodb_id = $row->cartodb_id; $latitude = $row->latitude; $longitude = $row->longitude; $url = "http://openwps.statkart.no/skwms1/wps.elevation?request=Execute&service=WPS&version=1.0.0&identifier=elevation&datainputs=[lat={$latitude};lon={$longitude};epsg=4326]"; $xml = simplexml_load_file($url); if ($xml->xpath('//wps:ExecuteResponse/wps:ProcessOutputs')) { $output = $xml->xpath('//wps:ExecuteResponse/wps:ProcessOutputs')[0]; $altitude = (string) $output->xpath('wps:Output[ows:Identifier/text()="elevation"]/wps:Data/wps:LiteralData')[0]; if ($altitude !== 'nan') { $altitude = round($altitude); $placename = (string) $output->xpath('wps:Output[ows:Identifier/text()="placename"]/wps:Data/wps:LiteralData')[0]; $ssrid = (int) $output->xpath('wps:Output[ows:Identifier/text()="ssrid"]/wps:Data/wps:LiteralData')[0]; $terrain = (string) $output->xpath('wps:Output[ows:Identifier/text()="terrain"]/wps:Data/wps:LiteralData')[0]; $cartodb->runSql("UPDATE spot SET altitude={$altitude}, placename='{$placename}', ssrid={$ssrid}, terrain='{$terrain}' WHERE cartodb_id = {$cartodb_id}"); //echo "<p>$placename $ssrid $altitude $terrain"; } } else {
<?php require_once 'cartodb.class.php'; require_once 'config.php'; date_default_timezone_set($timezone); $cartodb = new CartoDBClient($cartodb_config); if (!$cartodb->authorized) { error_log("uauth"); print 'There is a problem authenticating, check the key and secret.'; exit; } $lastHour = time() - 3600; $response = $cartodb->runSql("SELECT cartodb_id, timestamp, latitude, longitude FROM spot WHERE weather_symbol IS NULL AND timestamp > {$lastHour} ORDER BY timestamp DESC"); foreach ($response['return']['rows'] as $row) { $cartodb_id = $row->cartodb_id; $timestamp = $row->timestamp; $latitude = $row->latitude; $longitude = $row->longitude; $url = "http://api.yr.no/weatherapi/locationforecast/1.9/?lat={$latitude};lon={$longitude}"; $xml = simplexml_load_file($url); $time = date("Y-m-d\\TH:i:s\\Z", round($timestamp / 3600) * 3600); // Nearest hour $symbolTime = date("Y-m-d\\TH:00:00\\Z", $timestamp); // This hour $location = $xml->xpath("/weatherdata/product/time[@from='{$time}']/location")[0]; if (count($location)) { $location = $location[0]; $temperature = (int) $location->temperature['value']; $windDirection = (string) $location->windDirection['name']; $windSpeed = (int) $location->windSpeed['mps']; $wind = (string) $location->windSpeed['name'];
$jsonString = file_get_contents($feedUrl); $jsonArr = json_decode($jsonString, true); $response = $jsonArr['response']; if (isset($response['errors'])) { $error = $response['errors']['error']; error_log($error['code'] . $error['text']); print $error['description']; exit; } $response = $jsonArr['response']['feedMessageResponse']; if ($response['count'] == 1) { $messages = array($response['messages']['message']); } else { $messages = $response['messages']['message']; } $cartodb = new CartoDBClient($cartodb_config); if (!$cartodb->authorized) { error_log("uauth"); print 'There is a problem authenticating, check the key and secret.'; exit; } // Find max timestamp $response = $cartodb->runSql("SELECT MAX(timestamp) FROM spot"); $max = array_pop($response['return']['rows'])->max; foreach ($messages as $message) { if ($message['unixTime'] > $max) { // Add if newer $data = array('feed_id' => "'" . $feedId . "'", 'spot_id' => $message['id'], 'the_geom' => "'SRID=4326;POINT(" . $message['longitude'] . " " . $message['latitude'] . ")'", 'messenger_id' => "'" . $message['messengerId'] . "'", 'messenger_name' => "'" . $message['messengerName'] . "'", 'timestamp' => $message['unixTime'], 'message_type' => "'" . $message['messageType'] . "'", 'latitude' => $message['latitude'], 'longitude' => $message['longitude'], 'model_id' => "'" . $message['modelId'] . "'", 'show_custom_msg' => "'" . $message['showCustomMsg'] . "'", 'datetime' => "'" . date("Y-m-d H:i:s", $message['unixTime']) . "'", 'battery_state' => "'" . $message['batteryState'] . "'", 'hidden' => "'" . $message['hidden'] . "'", 'message_content' => "'" . (isset($message['messageContent']) ? $message['messageContent'] : '') . "'"); $response = $cartodb->insertRow('spot', $data); } }