querySingle("SELECT last FROM last_check"); if ($last_check ===null || date_add(new DateTime($last_check), DateInterval::createFromDateString('1 hour')) < new DateTime()) { $json = file_get_contents($json_address); if ($json !== false) { $decoded = json_decode($json, true); foreach($decoded['features'] as $value) { if(in_array($value['properties']['insee'], $villes_ALM)) { $ville = $base->querySingle("SELECT * FROM Villes WHERE code_INSEE=".$value['properties']['insee'].";", true); if ($ville == array()) { $base->query("INSERT INTO Villes VALUES (".$value['properties']['insee'].", \"".$value['properties']['name']."\");"); } $base->query("INSERT INTO chiffres VALUES(\"".$decoded['date']."\", ".$value['properties']['insee'].", ".$value['properties']['contributions'].");"); } } $base->query("DELETE FROM last_check;"); $base->query("INSERT INTO last_check VALUES ('".$decoded['date']."');"); $last_check = $decoded['date']; http_response_code(200); ?>{ "status": "updated"}{"status": "error in getting geojson file"}{"status": "doesn't need update"}