<?php

include '../inc/pdoDB.php';
include 'cScrape.php';
$scrape = new Scrape();
$url = 'http://public.health.oregon.gov/Preparedness/CurrentHazards/Pages/AirMonitoring.aspx';
$scrape->fetch($url);
$data = $scrape->removeNewlines($scrape->result);
$data = $scrape->fetchBetween('<table style="width:500px" class=ms-rteTable-1 summary=""><tbody>', '</tbody></table>', $data, true);
$rows = $scrape->fetchAllBetween('<tr', '</tr>', $data, true);
$aprildata = $scrape->fetchBetween('<table style="width:67.29%;height:73px" class=ms-rteTable-1 summary=""><tbody>', '</tbody></table>', $data, true);
$aprilrows = $scrape->fetchAllBetween('<tr', '</tr>', $aprildata, true);
$totalrows = array_merge($rows, $aprilrows);
$i = 0;
$records[] = NULL;
foreach ($totalrows as $id => $row) {
    $i++;
    if ($i == 1) {
        continue;
    }
    $record = array();
    $cells = $scrape->fetchAllBetween('<td', '</td>', $row, true);
    $record['Date'] = strip_tags($cells[0]);
    $record['Portland'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[1]));
    $record['Corvallis'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[2]));
    $record['Eureka'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[3]));
    $records[] = $record;
}
/* if ($records[0]) { */
// print_r($records);
// insert into DB
<?php

include '../inc/pdoDB.php';
include 'cScrape.php';
$scrape = new Scrape();
$url = 'http://www.doh.wa.gov/Topics/japan/monitor-history.htm';
$scrape->fetch($url);
$data = $scrape->removeNewlines($scrape->result);
$data = $scrape->fetchBetween('<table border="0" cellpadding="4">', '</table>', $data, true);
$rows = $scrape->fetchAllBetween('<tr', '</tr>', $data, true);
$i = 0;
foreach ($rows as $id => $row) {
    $i++;
    if ($i < 3) {
        continue;
    }
    $record = array();
    //    $cells = $scrape->fetchAllBetween('<font face="Arial" size="2">','</font>',$row,true);
    $cells = $scrape->fetchAllBetween('<font face=', '</font></td>', $row, true);
    $record['Date'] = strip_tags($cells[0]);
    $record['Richland'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[1]));
    $record['Seattle'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[2]));
    $record['Spokane'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[3]));
    $record['Tumwater'] = preg_replace("/[^.0-9\\s]/", "", strip_tags($cells[4]));
    $records[] = $record;
}
print_r($records);
// insert into DB
foreach ($records as $id => $record) {
    if (is_numeric($record['Richland'])) {
        $db->query("INSERT INTO government_readings (city_id, reading_value, reading_system, reading_date, radiation_type, is_verified) VALUES (4, '" . $record['Richland'] . "', '2', '" . date('Y-m-d 00:00:00', strtotime($record['Date'])) . "', 'beta', 1)");