Pugins Fixes + Dame Jídlo Fix

This commit is contained in:
GamerClassN7 2021-02-10 16:13:22 +01:00
parent 75dab33c9a
commit 1d44bd62e2
7 changed files with 91 additions and 6 deletions

View File

@ -22,7 +22,7 @@ class AirQuality extends VirtualDeviceManager
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi'], 'plugin');
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
DeviceManager::approved($this->virtual_device_name);

View File

@ -30,7 +30,7 @@ class AirQuality extends VirtualDeviceManager
$finalUrl = sprintf($this->api_uri, $this->city_sluig, $this->app_id);
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true);
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi']);
RecordManager::create($deviceId, $this->subdevice_type, $json['data']['aqi'], 'plugin');
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
DeviceManager::approved($this->virtual_device_name);

View File

@ -31,7 +31,7 @@ class CovidV2 extends VirtualDeviceManager
$json = json_decode(Utilities::CallAPI('GET', $finalUrl, ''), true)['data'];
foreach ($dataItems as $dataItem) {
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]]);
RecordManager::create($deviceId, strtolower($dataItem), end($json)[$this->name_index[$dataItem]], 'plugin');
}
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, strtolower($this->virtual_device_name));

85
app/plugins/DameJidlo.php Normal file
View File

@ -0,0 +1,85 @@
<?php
class DameJidlo extends VirtualDeviceManager
{
private $virtual_device_name = "Dáme Jídlo";
private $device_type = "virtual-device";
private $subdevice_type = "dame-jidlo";
public function deliveryTime($token)
{
// Generated by curl-to-PHP: http://incarnate.github.io/curl-to-php/
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://cz.fd-api.com/api/v5/tracking/active-orders?time_variation=Variation2');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Authority: cz.fd-api.com';
$headers[] = 'Sec-Ch-Ua: \"Chromium\";v=\"88\", \"Google Chrome\";v=\"88\", \";Not A Brand\";v=\"99\"';
$headers[] = 'Accept: application/json, text/plain, */*';
$headers[] = 'Authorization: Bearer ' . $token;
$headers[] = 'X-Pd-Language-Id: 2';
$headers[] = 'Sec-Ch-Ua-Mobile: ?0';
$headers[] = 'X-Fp-Api-Key: volo';
$headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36';
$headers[] = 'Origin: https://www.damejidlo.cz';
$headers[] = 'Sec-Fetch-Site: cross-site';
$headers[] = 'Sec-Fetch-Mode: cors';
$headers[] = 'Sec-Fetch-Dest: empty';
$headers[] = 'Referer: https://www.damejidlo.cz/';
$headers[] = 'Accept-Language: en-US,en;q=0.9,cs-CZ;q=0.8,cs;q=0.7';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return (isset(json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta']) ? json_decode($result, true)['data']['active_orders'][0]['delivery']['time']['eta'] : 0);
}
function make()
{
//Register the settings
$settingMng = new SettingsManager();
if (!($settingField = $settingMng->getByName("damejidlo_token","damejidlo"))) {
$settingMng->create("damejidlo_token", "", "damejidlo");
} else {
$bearer = $settingField['value'];
}
try {
if (DeviceManager::registeret($this->virtual_device_name)) {
$deviceId = DeviceManager::getDeviceByToken($this->virtual_device_name)['device_id'];
if (!$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, $this->subdevice_type)) {
SubDeviceManager::create($deviceId, $this->subdevice_type, '');
sleep(1);
$subDevice = SubDeviceManager::getSubDeviceByMaster($deviceId, strtolower($this->subdevice_type));
}
//if (!$this->fetchEnabled($deviceId,$subDevice['subdevice_id'])) die();
RecordManager::create($deviceId, $this->subdevice_type, $this->deliveryTime($bearer), 'plugin');
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
DeviceManager::approved($this->virtual_device_name);
}
return 'sucessful';
} catch (Exception $e) {
return 'exception: ' . $e->getMessage();
}
}
function translate($value){
if ($value == 0) {
return " Delivered";
} else if ($value <= 1) {
return "less " . $value;
}
return '';
}
}

View File

@ -29,7 +29,7 @@ class N7Day extends VirtualDeviceManager
$datediff = $now - $your_date;
$daysUntilN7Day = round($datediff / (60 * 60 * 24));
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day);
RecordManager::create($deviceId, $this->subdevice_type, $daysUntilN7Day, 'plugin');
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, $this->device_type);
DeviceManager::approved($this->virtual_device_name);

View File

@ -55,7 +55,7 @@ class OpenWeatherMap extends VirtualDeviceManager
}
RecordManager::create($deviceId, $this->subdevice_type, $json['weather'][0]['id']);
RecordManager::create($deviceId, $this->subdevice_type, $json['weather'][0]['id'], 'plugin');
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');
DeviceManager::approved($this->virtual_device_name);

View File

@ -52,7 +52,7 @@ class UsaElection extends VirtualDeviceManager
$OnePercent = ($Trump + $Biden + $Unknown) / 100;
foreach ($dataItems as $Category) {
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)));
RecordManager::create($deviceId, strtolower($Category), round(($$Category / $OnePercent)), 'plugin');
}
} else {
DeviceManager::create($this->virtual_device_name, $this->virtual_device_name, 'senzore-virtual');