1 | <?php |
||
2 | |||
3 | namespace Osln\Weather; |
||
4 | |||
5 | use Anax\Commons\ContainerInjectableInterface; |
||
6 | use Anax\Commons\ContainerInjectableTrait; |
||
7 | |||
8 | class Weather implements ContainerInjectableInterface |
||
9 | { |
||
10 | use ContainerInjectableTrait; |
||
11 | 6 | public function __construct() |
|
12 | { |
||
13 | 6 | $this->config = new LoadConfig(); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
14 | 6 | } |
|
15 | 4 | public function forecast($lat, $lon) : array |
|
16 | { |
||
17 | 4 | $url = "https://api.darksky.net/forecast/%1\$s/%2\$s,%3\$s?exclude=currently,flags,hourly,minutely&units=si"; |
|
18 | 4 | $key = $this->config->getKey("darksky"); |
|
19 | 4 | $urlFinal = sprintf($url, $key, $lat, $lon); |
|
20 | 4 | $data = $this->di->curl->fetch($urlFinal); |
|
0 ignored issues
–
show
|
|||
21 | // file_put_contents("forecast.json", json_encode($data)); |
||
22 | 4 | return [$data]; |
|
23 | } |
||
24 | |||
25 | 2 | public function getLastMonth($lat, $lon) : array |
|
26 | { |
||
27 | 2 | $currentTimes = $this->getArrayOfDays(); |
|
28 | 2 | $urls = []; |
|
29 | 2 | foreach ($currentTimes as $time) { |
|
30 | 2 | $key = $this->config->getKey("darksky"); |
|
31 | 2 | $url = "https://api.darksky.net/forecast/%1\$s/%2\$s,%3\$s,%4\$s?exclude=currently,flags,hourly,minutely&units=si"; |
|
32 | 2 | $urlFinal = sprintf($url, $key, $lat, $lon, $time); |
|
33 | 2 | $urls[] = $urlFinal; |
|
34 | } |
||
35 | // var_dump($urls); |
||
36 | 2 | $data = $this->di->curl->fetchMultiple($urls); |
|
0 ignored issues
–
show
|
|||
37 | // file_put_contents("historic.json", json_encode($data)); |
||
38 | 2 | return [$data]; |
|
39 | } |
||
40 | |||
41 | 2 | private function getArrayOfDays() : array |
|
42 | { |
||
43 | 2 | $times = []; |
|
44 | 2 | $now = time(); |
|
45 | 2 | for ($i=0; $i < 30; $i++) { |
|
46 | 2 | $now -= (24 * 60 * 60); |
|
47 | 2 | $times[] = $now; |
|
48 | } |
||
49 | 2 | return $times; |
|
50 | } |
||
51 | } |
||
52 |