function grab_stats($client, $tablename) { print "\n==========================================================\n"; print " {$tablename}\n"; print "==========================================================\n"; $output = array(); $result = $client->listMetrics(array()); $result = (array) $result; foreach ($result as $item) { foreach ($item as $metrics) { foreach ($metrics as $metric) { //echo 'METRIC='.serialize($metric); if (is_array($metric) && array_key_exists('MetricName', $metric) && array_key_exists('Dimensions', $metric)) { //echo $metric['MetricName'] . ' - ' // . $metric['Dimensions'][0]['Name'] . ' - ' // . $metric['Dimensions'][0]['Value'] . "\n"; $output[$metric['MetricName']] = grabber($client, $tablename, $metric['MetricName']); } } } } //echo 'grab_STATS='.serialize($output); return $output; //$cpuOutput = grabber($client, $tablename, 'CPUCreditBalance'); // per instance //$volOutput = grabber($client, $tablename, 'VolumeWriteOps'); // per volume //return array('cpu'=>$cpuOutput, 'vol'=>$volOutput); }
function grab_stats($client, $tablename) { print "\n==========================================================\n"; print " {$tablename}\n"; print "==========================================================\n"; $cpuOutput = grabber($client, $tablename, 'CPUCreditBalance'); // per instance $volOutput = grabber($client, $tablename, 'VolumeWriteOps'); // per volume return array('cpu' => $cpuOutput, 'vol' => $volOutput); }
if ($last_house == $hkey and $last_sex > $skey) { continue; } scraperwiki::save_var('last_sex', $skey); for ($year = 2009; $year >= 1989; $year = $year - 4) { if ($last_house == $hkey and $last_sex == $skey and $last_year < $year) { continue; } scraperwiki::save_var('last_year', $year); for ($number = 401; $number <= 460; $number++) { if ($last_house == $hkey and $last_sex == $skey and $last_year = $skey and $last_number > $number) { continue; } scraperwiki::save_var('last_number', $number); $url = "http://elecciones.gob.cl/SitioHistorico/paginas/{$year}/{$house}/distritos/candidatos/{$sex}/{$number}.htm"; $html = html_entity_decode(iconv("ISO-8859-1", "UTF-8", grabber($url, $curl_options)), ENT_COMPAT, 'UTF-8'); $dom = new simple_html_dom(); $dom->load($html); //check for empty file if (strpos($html, 'Para esta zona no hay elección') > 0) { continue; } $data = get_data($dom, $house, $sex, $year, $number - 400); scraperwiki::save_sqlite(array('year', 'house', 'district', 'i', 'sex'), $data); } scraperwiki::save_var('last_number', 400); $last_number = 400; } scraperwiki::save_var('last_year', 2009); $last_year = 2009; }
scraperwiki::sqlitecommit(); die();*/ //master file contains all the information about the files with external addresses $master_url = "https://spreadsheets.google.com/a/g.kohovolit.eu/spreadsheet/pub?hl=en_US&hl=en_US&key=0ApmBqWaAzMn_dHJlNjN2WWpaLVVXc005N2E0bTdVeXc&output=csv&dummy=4"; $master_html = grabber($master_url); //parse master csv $master = parse_csv($master_html); //get the last name/town scraped scraperwiki::save_var('run_first', 0); //temp!! $run_first = scraperwiki::get_var('run_first', 0); //for each parliament/town foreach ((array) $master as $key => $row) { if ($key >= $run_first) { $url = $row['link']; $html = grabber($url); $town = parse_csv($html); //add info about parliament, disambiguation foreach ((array) $town as $t_key => $t) { $town[$t_key]['parliament_code'] = $row['parliament_code']; $town[$t_key]['parliament_name'] = $row['parliament_name']; $town[$t_key]['term_name'] = $row['term']; if (!isset($town[$t_key]['disambiguation'])) { $town[$t_key]['disambiguation'] = ''; } } $towns[] = $town; scraperwiki::save_var('run_first', $key); } } //save data
curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 120); if (count($options) > 0) { foreach ($options as $option) { curl_setopt($ch, $option[0], $option[1]); } } return curl_exec($ch); //curl_close ($ch); } //http://www.camara.gov.br/internet/deputado/DepNovos_Lista.asp?Legislatura=41&Partido=QQ&SX=QQ&Todos=None&UF=QQ&condic=QQ&forma=lista&nome=&ordem=nome&origem= $curl_options = array(array(CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1')); require 'scraperwiki/simple_html_dom.php'; for ($term = 41; $term <= 54; $term++) { $url = "http://www.camara.gov.br/internet/deputado/DepNovos_Lista.asp?Legislatura={$term}&Partido=QQ&SX=QQ&Todos=None&UF=QQ&condic=QQ&forma=lista&nome=&ordem=nome&origem="; $html = grabber($url, $curl_options); $dom = new simple_html_dom(); $dom->load($html); $lis = $dom->find('div[id=content]', 0)->find('li'); foreach ($lis as $li) { $plain = trim($li->plaintext); $pa = explode('-', $plain); $na = explode('/', end($pa)); preg_match('/pk=([0-9]{1,})/', $li->find('a', 0)->href, $matches); $data[] = array('name' => trim($pa[0]), 'party' => trim($na[0]), 'state' => trim($na[1]), 'mp_pk_id' => $matches[1], 'term' => $term); } } scraperwiki::save_sqlite(array('term', 'mp_pk_id'), $data); /** * curl downloader, with possible options * @return html