From 977432606c0427afe32a674376d3303284f50a75 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 10 Jul 2023 20:00:09 +0200 Subject: [PATCH] . --- .idea/workspace.xml | 10 +++++-- scripts/cron/cron.php | 8 +++++- scripts/cron/traffic.php | 3 ++ scripts/lib/traffic.php | 61 +++++++++++++++++++++------------------- scripts/lib/velib.php | 6 ++-- 5 files changed, 52 insertions(+), 36 deletions(-) create mode 100644 scripts/cron/traffic.php diff --git a/.idea/workspace.xml b/.idea/workspace.xml index e4085bc..1540e88 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,11 @@ + - + + + diff --git a/scripts/cron/cron.php b/scripts/cron/cron.php index 13b9103..7e54713 100644 --- a/scripts/cron/cron.php +++ b/scripts/cron/cron.php @@ -219,7 +219,13 @@ function cronTraffic($cronmin, $force = false) { $limit = 60; } if ($force || !file_exists($cache) || filemtime($cache) < time() - $limit) { - $traffic = array('time' => date('H:i', time() + ($departure_in * 60)), 'jams' => trafficJams(), 'car' => itineraryIssy('driving'), 'subway' => itineraryIssy('transit'), 'bike' => itineraryIssy('bicycling')); + $traffic = [ + 'time' => date('H:i', time() + ($departure_in * 60)), + 'jams' => trafficJams(), + 'car' => itineraryIssy(), + 'subway' => itineraryIssy('transit'), + 'bike' => itineraryIssy('bicycling') + ]; $json = json_encode($traffic); file_put_contents($cache, $json); if (isset($_GET['force'])) { diff --git a/scripts/cron/traffic.php b/scripts/cron/traffic.php new file mode 100644 index 0000000..f050663 --- /dev/null +++ b/scripts/cron/traffic.php @@ -0,0 +1,3 @@ +loadHTMLFile('http://www.sytadin.fr/'); - $e = $dom->getElementById('cumul_bouchon'); - if (null === $e) { - return '??'; - } - $i = $e->getElementsByTagName('img')->item(0); - return intval((string)$i->getAttribute('alt')); +function trafficJams() { + $dom = new DOMDocument(); + @$dom->loadHTMLFile('http://www.sytadin.fr/'); + $e = $dom->getElementById('cumul_bouchon'); + if (null === $e) { + return '??'; + } + $i = $e->getElementsByTagName('img')->item(0); + return intval((string)$i->getAttribute('alt')); } -function itineraryIssy($mode = 'driving') -{ - global $departure_in; - $key = 'AIzaSyCmBfccaAxrhp5CH27sydD2n0jE-xFp9A8'; - //$origin = '5 rue de Rochechouart, Paris'; - $origin = 'place_id:ChIJISH0cEBu5kcRtWqJGS8R9vc'; - // $destination = '11 rue René Jacques, Issy-les-moulineaux'; - $destination = 'place_id:ChIJ_zVpOo965kcRLVwpXuatEOo'; - $departure = time() + ($departure_in * 60); - $transit_mode = ''; - if ($mode == 'transit') { - $transit_mode = '&transit_mode=rail'; - } - $res = json_decode(file_get_contents('https://maps.googleapis.com/maps/api/directions/json?mode=' . $mode . $transit_mode . '&languages=fr&departure_time=' . $departure . '&origin=' . urlencode($origin) . '&destination=' . urlencode($destination) . '&key=' . $key), true); - if ($mode == 'driving') { - return round($res['routes'][0]['legs'][0]['duration_in_traffic']['value'] / 60); - } else { - return round($res['routes'][0]['legs'][0]['duration']['value'] / 60); - } +function itineraryIssy($mode = 'driving') { + global $departure_in; + $key = 'AIzaSyCmBfccaAxrhp5CH27sydD2n0jE-xFp9A8'; + //$origin = '5 rue de Rochechouart, Paris'; + //$origin = 'place_id:ChIJISH0cEBu5kcRtWqJGS8R9vc'; + if ($mode === 'driving') { + $origin = 'place_id:ChIJ28lUzD5u5kcRQo1KXiy9xys'; + } else { + $origin = 'place_id:ChIJfdFmjj9u5kcRUyCLnw-tkIU'; + } + // $destination = '11 rue René Jacques, Issy-les-moulineaux'; + $destination = 'place_id:ChIJ_zVpOo965kcRLVwpXuatEOo'; + $departure = time() + ($departure_in * 60); + $transit_mode = ''; + if ($mode == 'transit') { + $transit_mode = '&transit_mode=rail'; + } + $res = json_decode(file_get_contents('https://maps.googleapis.com/maps/api/directions/json?mode=' . $mode . $transit_mode . '&languages=fr&departure_time=' . $departure . '&origin=' . urlencode($origin) . '&destination=' . urlencode($destination) . '&key=' . $key), true); + if ($mode == 'driving') { + return round($res['routes'][0]['legs'][0]['duration_in_traffic']['value'] / 60) + 10; + } else { + return round($res['routes'][0]['legs'][0]['duration']['value'] / 60); + } } \ No newline at end of file diff --git a/scripts/lib/velib.php b/scripts/lib/velib.php index 2ccd0d5..7e17f18 100644 --- a/scripts/lib/velib.php +++ b/scripts/lib/velib.php @@ -11,12 +11,12 @@ function velibStations($force = false) $limit = 60; } - if ($force || !file_exists($cache) || filemtime($cache) < time() - $limit) { + if ($force || !file_exists($cache) || filemtime($cache) < (time() - $limit)) { $allcache = __DIR__ . '/../../cache/velib.all.json'; - $ffversion = rand('96', '105'); + $ffversion = rand('105', '116'); $thversion = rand('1', '100'); - `curl 'https://velib-metropole-opendata.smoove.pro/opendata/Velib_Metropole/station_status.json' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv$ffversion.0) Gecko/20100101 Firefox/$ffversion.0 TortugaHome/$thversion.0' --output $cache`; + `curl 'https://velib-metropole-opendata.smoove.pro/opendata/Velib_Metropole/station_status.json' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv$ffversion.0) Gecko/20100101 Firefox/$ffversion.0 TortugaHome/$thversion.0' --output $allcache`; $alldata = json_decode(file_get_contents($allcache), true); $stations = ['Cadet' => '9101', 'Bleue' => '9113', 'Folies bergères' => '9011', 'Square Montholon' => '9009', 'Le Pelletier' => '9014']; -- 2.39.5