parsing
This commit is contained in:
parent
41678d3373
commit
4cc02073d5
12
parse-json.php
Normal file
12
parse-json.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
include 'config.php';
|
||||
|
||||
$sql = "SELECT scans.id, content FROM scans inner join sites on sites.id=scans.site where sites.type='json' and parsed=0";
|
||||
$sql = "SELECT scans.id, content FROM scans where id = 2235";
|
||||
foreach ($pdo->query($sql) as $row){
|
||||
$fromJSON = json_decode($row['content']);
|
||||
foreach ($fromJSON->features as $feature){
|
||||
$feature = $feature->attributes;
|
||||
var_dump($feature);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user