diff --git a/scraper.php b/scraper.php index 87fec18..6a5e84f 100644 --- a/scraper.php +++ b/scraper.php @@ -1,27 +1,57 @@ -load($html); -// print_r($dom->find("table.list")); -// -// // Write out to the sqlite database using scraperwiki library -// scraperwiki::save_sqlite(array('name'), array('name' => 'susan', 'occupation' => 'software developer')); -// -// // An arbitrary query against the database -// scraperwiki::select("* from data where 'name'='peter'") +require 'scraperwiki.php'; -// You don't have to do things with the ScraperWiki library. -// You can use whatever libraries you want: https://morph.io/documentation/php -// All that matters is that your final data is written to an SQLite database -// called "data.sqlite" in the current working directory which has at least a table -// called "data". -?> +date_default_timezone_set('Australia/Hobart'); + +require 'simple_html_dom.php'; + +$url = 'http://www.huonvalley.tas.gov.au/services/planning-2/planningnotices/'; + +$dapage = $url; +$html = scraperwiki::scrape($dapage); +$dom = new simple_html_dom(); +$dom->load($html); +$darow = $dom->find("table#list tbody tr"); +print 'number of records: ' . sizeof($darow); +foreach ($darow as $thisrow) { +// +// DA-6-2015 - Dwelling and Carport - Land - (CT128515-1) directly to the south of 14 Smyley Street, Franklin +// Smyley Street, Franklin, Tasmania, Australia +// 15 Sep 2015 +// 29 Sep 2015 +// +// Copy of Plans for display +// +// + // var_dump($thisrow); + + $record = array(); + $cells = $thisrow->find("td"); + + var_dump($cells); + + $refdesc = $cells[0]; + $delim = ' - '; + $delimpos = stripos($refdesc, $delim); + $record['council_reference'] = substr($refdesc, 0, $stripos - 1); + $record['description'] = substr($refdesc, $stripos + strlen(delim)); + $record['address'] = $cells[1]; + $record['date_received'] = $cells[2]; + $record['on_notice_to'] = date('Y-m-d', $cells[3]); + $record['info_url'] = $cells[4]->find('a')->href; + $record['comment_url'] = 'http://www.huonvalley.tas.gov.au/services/planning-2/how-to-make-a-representation/'; + $record['date_scraped'] = date('Y-m-d'); + +// var_dump($record); + +// $existingRecords = scraperwiki::select("* from data where `council_reference`='" . $record['council_reference'] . "'"); +// if (count($existingRecords) == 0) { +// print ("Saving record " . $record['council_reference'] . "\n"); + //print_r ($record); + scraperwiki::save_sqlite(array('council_reference'), $record, 'data'); +// } else { +// print ("Skipping already saved record " . $record['council_reference'] . "\n"); +// } +} +?> \ No newline at end of file