Added a paper config file with airly settings, fixed some minor issues with airly data not being printed.
This commit is contained in:
@@ -146,8 +146,10 @@ class Main extends Controller
|
|||||||
public function airly(Request $request)
|
public function airly(Request $request)
|
||||||
{
|
{
|
||||||
$airly = new Airly();
|
$airly = new Airly();
|
||||||
$this->paper->sendImagePrint('cloud.png');
|
$this->paper->sendImagePrint($airly->icon);
|
||||||
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
|
$this->paper->sendHeaderPrint('Jakość powietrza:' . PHP_EOL . date('H:i d-m-Y'));
|
||||||
|
$airly->setStations(config('paper.airly.stations'));
|
||||||
|
|
||||||
foreach ($airly->getStations() as $stationId) {
|
foreach ($airly->getStations() as $stationId) {
|
||||||
$stationInfo = $airly->getStationInfo($stationId);
|
$stationInfo = $airly->getStationInfo($stationId);
|
||||||
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
|
$this->paper->sendHeaderPrint($stationInfo['address']['locality'] . ' ' . $stationInfo['address']['route']);
|
||||||
|
|||||||
@@ -6,18 +6,28 @@ namespace App\Paper;
|
|||||||
class Airly
|
class Airly
|
||||||
{
|
{
|
||||||
|
|
||||||
private $apiKey = '8b6d77b2950e4e018b0684912bf7b9ed';
|
private $apiKey;
|
||||||
|
|
||||||
|
public $icon = 'cloud';
|
||||||
|
|
||||||
private $stations = ['2210', '2256', '2180'];
|
private $stations = [];
|
||||||
private $airlyApi = 'https://airapi.airly.eu/v1';
|
private $airlyApi = 'https://airapi.airly.eu/v1';
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->apiKey = config('paper.airly.api_key');
|
||||||
|
}
|
||||||
|
|
||||||
public function getStations()
|
public function getStations()
|
||||||
{
|
{
|
||||||
return $this->stations;
|
return $this->stations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setStations($stations){
|
||||||
|
$this->stations = $stations;
|
||||||
|
}
|
||||||
|
|
||||||
function getStationInfo($stationId)
|
function getStationInfo($stationId)
|
||||||
{
|
{
|
||||||
return json_decode(file_get_contents(sprintf('%s/sensors/%d?apikey=%s', $this->airlyApi, $stationId, $this->apiKey)), 1);
|
return json_decode(file_get_contents(sprintf('%s/sensors/%d?apikey=%s', $this->airlyApi, $stationId, $this->apiKey)), 1);
|
||||||
|
|||||||
15
config/paper.php
Normal file
15
config/paper.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: k
|
||||||
|
* Date: 15.04.2018
|
||||||
|
* Time: 19:53
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
return ['airly' =>
|
||||||
|
[
|
||||||
|
'api_key' => '8b6d77b2950e4e018b0684912bf7b9ed',
|
||||||
|
'stations' => ['2210', '2256', '2180'],
|
||||||
|
]
|
||||||
|
];
|
||||||
Reference in New Issue
Block a user