-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.php
44 lines (36 loc) · 1.05 KB
/
data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
require_once 'phar://goutte.phar/autoload.php';
use Goutte\Client;
$cities = array('BRU', 'ANR', 'GNE', 'LGG', 'CRL');
$time = file_exists('cache/data') ? filemtime('cache/data') : 0;
if ($time && time()-$time <= 60*60) {
$result = json_decode(file_get_contents('cache/data'), true);
}
else {
$client = new Client();
$indexes = $client->request('GET', 'http://deus.irceline.be/~celinair/index/subindex_air.php?lan=en')->filter('img[alt!=index]')->each(function($node, $i) {
return $node->getAttribute('alt');
});
$result = array_combine($cities, array_slice($indexes, 0, 5));
if (!file_exists('cache')) {
mkdir('cache');
}
file_put_contents('cache/data', json_encode($result));
}
if (isset($_GET['city'])) {
if (in_array($_GET['city'], $cities)) {
$city = $_GET['city'];
$status = 'ok';
$response = $result[$city];
}
else {
$status = 'error';
$response = 'Unknown city';
}
}
else {
$status = 'ok';
$response = $result;
}
header('Content-Type: text/plain');
echo json_encode(array('status' => $status, 'response' => $response));