Ejemplo n.º 1
0
 /**
  * A validation rule that checks the validity of a town.
  *
  * @param  string  $attribute
  * @param  mixed  $value
  * @param  array  $parameters
  * @return void
  */
 public function validateTown($attribute, $value, array $parameters)
 {
     return (bool) town($value, !!head($parameters));
 }
$h3s = $dom->find('h3');
array_shift($h3s);
//foreach region (kraj)
foreach ($h3s as $key => $h3) {
    $table = $dom->find('table', $key);
    $trs = $table->find('tr');
    array_shift($trs);
    array_shift($trs);
    $supregion = $h3->plaintext;
    //foreach county (okres)
    foreach ($trs as $tr) {
        $tds = $tr->find('td');
        $data = array('supregion' => $supregion, 'region' => $tds[1]->plaintext, 'region_code' => $tds[0]->plaintext, 'link' => html_entity_decode($tds[3]->find('a', 0)->href));
        scraperwiki::save_sqlite(array('region_code'), $data, 'county');
        //get all towns
        scraperwiki::save_sqlite(array('town_code'), town($data['link'], $data['region_code'], $data['region']), 'town');
    }
}
function town($link, $region_code, $region)
{
    $out = array();
    $url = 'http://www.volby.cz/pls/ps2010/' . $link;
    //********************************
    $html = str_replace(' ', '', iconv('ISO-8859-2', 'UTF-8//TRANSLIT', scraperwiki::scrape($url)));
    $dom = new simple_html_dom();
    $dom->load($html);
    $tables = $dom->find('table');
    foreach ($tables as $table) {
        $trs = $table->find('tr');
        array_shift($trs);
        array_shift($trs);