parse worldometer mit todesfällen und genesungen

This commit is contained in:
Göran Heinemann 2020-03-06 13:13:11 +01:00
parent d4911399f1
commit 1757e9ca5f

View File

@ -2,7 +2,7 @@
<?php
include "config.php";
$sql = "SELECT * FROM scans WHERE site=2 limit 1";
$sql = "SELECT * FROM scans WHERE site=2";
$stmt = $pdo->query($sql);
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($data as $scan){
@ -12,23 +12,33 @@ foreach ($data as $scan){
$table = $table->childNodes[1];
$data = $table->childNodes[1];
$parts = $data->childNodes;
$linetotal = array();
$linetotal[] = $table->childNodes[2]->childNodes[0]->childNodes[0]->textContent;
$linetotal[] = intval(str_replace(",", "", $table->childNodes[2]->childNodes[0]->childNodes[2]->textContent));
$document = array();
$document[] = $linetotal;
for ($i = 0; $i < $parts->length; $i++) {
$country = array();
$p2 = $parts[$i]->childNodes;
$country[] = $p2[0]->textContent;
$country[] = $p2[2]->textContent;
$country[] = intval(str_replace(",", "", $p2[2]->textContent));
$country[] =intval(str_replace(",", "", $p2[6]->textContent));
$country[] =intval(str_replace(",", "", $p2[10]->textContent));
$country[] =intval(str_replace(",", "", $p2[12]->textContent));
$document[] = $country;
}
$scanid = $scan['id'];
foreach ($document as $entry){
$sql = "INSERT INTO `data`(`scan`, `place`, `amount`) VALUES (?, ?, ?)";
$sql = "INSERT INTO `data`(`scan`, `place`, `amount`, deaths, active, cured) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(1, $scanid);
$stmt->bindParam(2, $entry[0]);
$stmt->bindParam(3, $entry[1]);
$stmt->bindParam(4, $entry[2]);
$stmt->bindParam(5, $entry[3]);
$stmt->bindParam(6, $entry[4]);
$stmt->execute();
if($stmt->errorInfo()[0] != '00000' and $stmt->errorInfo()[0] != '23000' and $stmt->errorInfo()[0] != '22007')
var_dump($stmt->errorInfo());