wyciszenie zaciągania danych o wodowskazach

pull/1/head
Pawel 2020-08-30 15:09:59 +02:00
rodzic b919de21e9
commit 23425c2eb9
1 zmienionych plików z 10 dodań i 10 usunięć

Wyświetl plik

@ -1,16 +1,16 @@
<?php
ini_set('max_execution_time', 1800);
function getAllIdsFromImgw () {
$res = shell_exec("curl 'https://hydro.imgw.pl/api/map/?category=hydro' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: pl,en-US;q=0.7,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://hydro.imgw.pl/' -H 'Cookie: SRV_=shsrv02.imgw.pl_SRV' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'");
$res = shell_exec("curl --silent 'https://hydro.imgw.pl/api/map/?category=hydro' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: pl,en-US;q=0.7,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://hydro.imgw.pl/' -H 'Cookie: SRV_=shsrv02.imgw.pl_SRV' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'");
return json_decode($res);
}
function getRequestedIds ($base64json) {
$data = json_decode(base64_decode($base64json));
$res = array();
foreach ($data as $row) {
if (strstr($row, '.')) {
@ -18,11 +18,11 @@
$row = $tmp[1];
}
$res[] = $row;
}
}
return $res;
}
function dataFileIsToOld ($filename, $olderThanSeconds=1800) {
function dataFileIsToOld ($filename, $olderThanSeconds=1800) {
if (!file_exists($filename)) {
return true;
}
@ -33,7 +33,7 @@
$requestIds = getRequestedIds($argv[1]);
if(!file_exists('imgwpodest_data')){
$oldmask = umask(0);
$oldmask = umask(0);
mkdir('imgwpodest_data',0777);
umask($oldmask);
}
@ -42,9 +42,9 @@
foreach($allIds as $row){
if (!in_array($row->i, $requestIds)) continue;
if (dataFileIsToOld('imgwpodest_data/'.$row->i.'.json', 3600)) {
$json = shell_exec("curl 'https://hydro.imgw.pl/api/station/hydro/?id=".$row->i."' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: pl,en-US;q=0.7,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://hydro.imgw.pl/' -H 'Cookie: SRV_=shsrv01.imgw.pl_SRV' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'");
$json = shell_exec("curl --silent 'https://hydro.imgw.pl/api/station/hydro/?id=".$row->i."' -H 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Accept-Language: pl,en-US;q=0.7,en;q=0.3' --compressed -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'Referer: https://hydro.imgw.pl/' -H 'Cookie: SRV_=shsrv01.imgw.pl_SRV' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache'");
file_put_contents('imgwpodest_data/'.$row->i.'.json', $json);
}
@ -54,7 +54,7 @@
$tmp_river = explode(' (',$subdata->status->river);
$trends = array(2 => 0, 3 => -1, 4 => 1);
$result[$row->i] = array(
'id' => $row->i,
'nazwa' => $subdata->status->description,
@ -70,7 +70,7 @@
'water_gauge_zero_ordinate' => $subdata->status->waterGaugeZeroOrdinate,
'lat' => $row->la,
'lon' => $row->lo
);
);
}
echo json_encode($result);