Compare commits
No commits in common. "d2c1ccb8cb9a01df20462e2a5d56d9a171af9eb9" and "ca02c88d38d7f16bcb94e5f32c7f8fe38684b8ef" have entirely different histories.
d2c1ccb8cb
...
ca02c88d38
@ -1,2 +0,0 @@
|
|||||||
DROP VIEW IF EXISTS chiffres_diff;
|
|
||||||
CREATE VIEW IF NOT EXISTS chiffres_diff AS SELECT date, code_INSEE, nombre - LAG(nombre) OVER (PARTITION BY code_INSEE ORDER BY date) AS nombre FROM chiffres;
|
|
@ -1,8 +0,0 @@
|
|||||||
|
|
||||||
<?php
|
|
||||||
|
|
||||||
$villes_ALM = array(49007, 49015, 49020, 49028, 49035, 49048, 49055, 4129, 49130, 49135, 49307, 49200, 49214, 49223, 49241, 49246, 49377, 49267, 49271, 49294, 49298, 49306, 49278, 49326, 49329, 49338, 49339, 49353, 49434);
|
|
||||||
|
|
||||||
$json_address = "https://www.barometre-velo.fr/stats/progress.geojson";
|
|
||||||
|
|
||||||
$base = new SQlite3('barometre.sqlite');
|
|
32
ingest.php
32
ingest.php
@ -1,32 +0,0 @@
|
|||||||
<?php
|
|
||||||
require "config.inc.php";
|
|
||||||
|
|
||||||
// Mise à jour des données
|
|
||||||
$last_check = $base->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"}<?php
|
|
||||||
} else {
|
|
||||||
http_response_code(500);
|
|
||||||
?>{"status": "error in getting geojson file"}<?php
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
http_response_code(304);
|
|
||||||
?>{"status": "doesn't need update"}<?php
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user