-
Notifications
You must be signed in to change notification settings - Fork 91
tankerkoenig
psilo909 edited this page Apr 17, 2016
·
38 revisions
This plugin requires lib requests. You can install this lib with:
sudo pip3 install requests --upgrade
You need your own personal API key for TankerKoenig. For your own key register to https://creativecommons.tankerkoenig.de
README.md: https://github.com/smarthomeNG/smarthome/tree/develop/plugins/tankerkoenig
logic.conf:
[PetrolStationCSVLogic] filename = petrol_station_csv_logic.py cycle = 360 crontab = init
Logic "petrol_station_csv_logic.py":
import csv with open('/var/run/petrol_stations.csv', 'w') as csvfile: fieldnames = ['place', 'brand', 'houseNumber', 'street', 'id', 'lng', 'name', 'lat', 'price', 'dist', 'isOpen', 'postCode'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() for element in sh.tankerkoenig.get_petrol_stations(sh._lat, sh._lon, 'diesel', 'price', rad='10'): writer.writerow(element)
New file in lib/fuel/fuel.php
<?php
require_once const_path_system.'service.php';
/**
* This class is the base class of all phone systems
*/
class fuel extends service
{
/**
* initialization of some parameters
*/
public function init($request)
{
$this->debug = ($request['debug'] == 1);
$this->server = config_phone_server;
$this->port = config_phone_port;
$this->user = config_phone_user;
$this->pass = config_phone_pass;
}
/**
* prepare the data
*/
public function prepare()
{
foreach ($this->data as $id => $ds)
{
if ($ds['name'] != '')
{
if ($ds['brand'] == '' || $ds['brand'] == 'Freie') {
if (strpos($ds['name'], "BK-Tankstelle") !== false ) {
$ds['brand'] = 'BK';
} else if (strpos($ds['name'], "AEZ") !== false ) {
$ds['brand'] = 'aez';
}
}
if ($ds['brand'] != '' and is_file(const_path.'pics/fuel/'.$ds['brand'].'.jpg'))
$ds['pic'] = $ds['brand'].'.jpg';
elseif ($ds['brand'] != '' and is_file(const_path.'pics/fuel/'.$ds['brand'].'.png'))
$ds['pic'] = $ds['brand'].'.png';
else
$ds['pic'] = 'fuel_station.svg';
if (strlen($ds['name']) > 22) {
$ds['text'] = substr($ds['name'],0,22)."...";
} else {
$ds['text'] = $ds['name'];
}
$ds['gmaps_link'] = "http://www.google.com/maps/place/".$ds['lat'].",".$ds['lng'];
// dir > 0 incomming
if ($ds['isOpen'] == 'True')
{
$ds['openpic'] = 'open.png';
$ds['openalt'] = trans('fuel', 'open');
}
$ds['address'] = $ds['place'].", ".$ds['street']." ".$ds['housenumber'];
// dir < 0 outgoing
if ($ds['dir'] < 0)
{
$ds['openpic'] = 'closed.png';
$ds['openalt'] = trans('fuel', 'closed');
}
$ret[] = $ds;
}
}
$this->data = $ret;
}
}
?>
</php>
Die aktuellen Release Notes und die Release Notes der zurückliegenden Versionen sind in der Dokumentation im Abschnitt Release Notes zu finden.