From 4cc02073d538065c941bd9aedd188b22f2fad8d6 Mon Sep 17 00:00:00 2001 From: Goeran Heinemann Date: Mon, 9 Mar 2020 19:26:19 +0100 Subject: [PATCH] parsing --- parse-json.php | 12 ++++++++++++ parse-worldometers.php | 32 +++++++++++++++++++++++++++++--- 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 parse-json.php diff --git a/parse-json.php b/parse-json.php new file mode 100644 index 0000000..f6610b0 --- /dev/null +++ b/parse-json.php @@ -0,0 +1,12 @@ +query($sql) as $row){ + $fromJSON = json_decode($row['content']); + foreach ($fromJSON->features as $feature){ + $feature = $feature->attributes; + var_dump($feature); + } +} \ No newline at end of file diff --git a/parse-worldometers.php b/parse-worldometers.php index b5ff345..986b753 100755 --- a/parse-worldometers.php +++ b/parse-worldometers.php @@ -3,6 +3,7 @@ include "config.php"; $sql = "SELECT * FROM scans WHERE site=2 and parsed=0"; +$sql = "SELECT * FROM scans WHERE id=2231"; //$sql = "SELECT * FROM scans WHERE id=(SELECT MAX(id) FROM scans WHERE site=2)"; $stmt = $pdo->query($sql); $data = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -15,6 +16,28 @@ foreach ($data as $scan){ $parts = $data->childNodes; $linetotal = array(); $linetotal[] = $table->childNodes[2]->childNodes[0]->childNodes[0]->textContent; + $headline = $table->childNodes[0]->childNodes[0]->childNodes; + + $deathsCol = 0; + $recoveredCol = 12; + $activeCol = 16; + for ($j = 0; $j < $headline->length; $j++){ + //var_dump($j); + //var_dump($headline[$j]); + if ($headline[$j]->textContent == 'TotalDeaths'){ + $deathsCol = $j; + } + if ($headline[$j] == 'TotalRecovered'){ + $recoveredCol = $j; + } + if ($headline[$j] == 'ActiveCases'){ + var_dump("test"); + $activeCol = $j; + } + } + + echo $deathsCol . ' ' . $recoveredCol . ' ' . $activeCol; + $linetotal[] = intval(str_replace(",", "", $table->childNodes[2]->childNodes[0]->childNodes[2]->textContent)); $document = array(); $document[] = $linetotal; @@ -25,12 +48,15 @@ foreach ($data as $scan){ /*for ($j=0; $j < $p2->length; $j++){ var_dump($p2[$j]->textContent); }*/ - $deaths = (strpos($p2[6]->textContent, "+") !== false?$p2[8]->textContent:$p2[6]->textContent); - $active = (strpos($p2[6]->textContent, "+") !== false?$p2[16]->textContent:$p2[10]->textContent); + //$deaths = (strpos($p2[6]->textContent, "+") !== false?$p2[8]->textContent:$p2[6]->textContent); + //$active = (strpos($p2[6]->textContent, "+") !== false?$p2[16]->textContent:$p2[10]->textContent); + $deaths = $p2[$deathsCol]->textContent; + $recovered = $p2[$recoveredCol]->textContent; + $active = $p2[$activeCol]->textContent; $country[] = intval(str_replace(",", "", $p2[2]->textContent)); $country[] =intval(str_replace(",", "", $deaths)); $country[] =intval(str_replace(",", "", $active)); - $country[] =intval(str_replace(",", "", $p2[12]->textContent)); + $country[] =intval(str_replace(",", "", $recovered)); $document[] = $country; }