Compare commits
2 Commits
ca02c88d38
...
d2c1ccb8cb
Author | SHA1 | Date | |
---|---|---|---|
d2c1ccb8cb | |||
27a63df5e2 |
2
01-diff-view.sql
Normal file
2
01-diff-view.sql
Normal file
@ -0,0 +1,2 @@
|
||||
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;
|
8
config.inc.php
Normal file
8
config.inc.php
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
<?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
Normal file
32
ingest.php
Normal file
@ -0,0 +1,32 @@
|
||||
<?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