function errorHandler($errno, $errstr, $errfile, $errline) { // if error has been surpressed with an @ // see: http://php.net/manual/en/function.set-error-handler.php if (error_reporting() == 0) { return; } global $script; $etb = errorParserStack($errno, $errstr, $script); scraperwiki::sw_dumpMessage($etb); return true; }
static function gb_postcode_to_latlng($postcode) { if (is_null($postcode)) { return null; } $ds = SW_DataStoreClass::create(); $result = $ds->postcodeToLatLng($postcode); if (!$result[0]) { scraperwiki::sw_dumpMessage(array('message_type' => 'console', 'content' => 'Warning: ' + sprintf('%s: %s', $result[1], $postcode))); return null; } return $result[1]; }
static function save_sqlite($unique_keys, $data, $table_name = "swdata", $verbose = 2) { $ds = SW_DataStoreClass::create(); if (count($data) == 0) { return; } if (!array_key_exists(0, $data)) { $data = array($data); } # convert special types foreach ($data as &$row) { foreach ($row as $key => &$value) { if ($value instanceof DateTime) { $new_value = clone $value; $new_value->setTimezone(new DateTimeZone('UTC')); $value = $new_value->format(DATE_ISO8601); assert(strpos($value, "+0000") !== FALSE); $value = str_replace("+0000", "", $value); } } } $result = $ds->request(array('maincommand' => 'save_sqlite', 'unique_keys' => $unique_keys, 'data' => $data, 'swdatatblname' => $table_name)); if (property_exists($result, 'error')) { throw new Exception($result->error); } if ($verbose == 2) { $sdata = $data[0]; $pdata = array(); foreach ($sdata as $key => $value) { $pdata[scraperwiki::unicode_truncate($key, 50)] = scraperwiki::unicode_truncate($value, 50); } if (count($data) >= 2) { $pdata["number_records"] = "Number Records: " . count($data); } scraperwiki::sw_dumpMessage(array('message_type' => 'data', 'content' => $pdata)); } return $result; }
$dict = array('message_type' => 'console', 'encoding' => "base64", 'content' => base64_encode($data)); scraperwiki::httpresponseheader("Content-Type", "image/png"); scraperwiki::sw_dumpMessage($dict); $url = "http://scraperwiki.com/media/images/intro_slides/intro4.png"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curl); curl_close($curl); //print $data; $dict = array('message_type' => 'console', 'encoding' => "base64", 'content' => base64_encode($data)); scraperwiki::httpresponseheader("Content-Type", "image/png"); scraperwiki::sw_dumpMessage($dict); $url = "http://scraperwiki.com/media/images/intro_slides/intro4.png"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curl); curl_close($curl); //print $data; $dict = array('message_type' => 'console', 'encoding' => "base64", 'content' => base64_encode($data)); scraperwiki::httpresponseheader("Content-Type", "image/png"); scraperwiki::sw_dumpMessage($dict); $url = "http://scraperwiki.com/media/images/intro_slides/intro4.png"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curl); curl_close($curl); //print $data; $dict = array('message_type' => 'console', 'encoding' => "base64", 'content' => base64_encode($data)); scraperwiki::httpresponseheader("Content-Type", "image/png"); scraperwiki::sw_dumpMessage($dict);