From baaa2990da0c2c21224c77729bd867b4d1f969c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hauke=20Z=C3=BChl?= Date: Fri, 10 Jan 2020 12:27:34 +0100 Subject: [PATCH] Using yaml config file --- php/muell.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/php/muell.php b/php/muell.php index 4c7be8f..6c87a36 100755 --- a/php/muell.php +++ b/php/muell.php @@ -7,26 +7,39 @@ * * Die Angaben hier im Skript stehen für Hörstel als Kommune und Im Wiesengrund als Strasse * - * Um die Daten an Telegram zu senden, musst du dir ein Skript/Progtramm schreiben, dass die API + * Um die Daten an Telegram zu senden, musst du dir ein Skript/Programm schreiben, dass die API * von Telegram verwendet und Daten an dich oder deine Gruppe senden kann! + * + * Beispiel für eine Konfigurationsdatei: + * tgReceiver: + * kommune: 2601 + * strasse: 2146 + * pathBot: '~/bin/YMBot' */ $currentYear = date('Y'); $dateRange = sprintf('%s0101-%s1231', $currentYear, $currentYear); $key = 'e21758b9c711463552fb9c70ac7d4273'; -$kommune = 2601; -$strasse = 2146; -$tgReceiverId = 0; // Positive values are users, negative values are group IDs -$pathToBot = '~/bin/YMBot'; + +$home = getenv('HOME'); +$configFilePath = sprintf('%s/.muell.yaml', $home); + +// Read the config file if existing +if (!file_exists($configFilePath)) { + echo "Bitte .muell.yaml im Homeverzeichnis anlegen!\n"; + return 1; +} + +$config = yaml_parse_file($configFilePath); $url = sprintf('https://api.abfall.io/?key=%s&modus=d6c5855a62cf32a4dadbc2831f0f295f&waction=export_csv', $key); $ch = curl_init($url); $data = [ - 'f_id_kommune' => $kommune, - 'f_id_strasse' => $strasse, + 'f_id_kommune' => $config['kommune'], + 'f_id_strasse' => $config['strasse'], 'f_id_abfalltyp_0' => 50, 'f_id_abfalltyp_1' => 161, 'f_id_abfalltyp_2' => 53, @@ -71,7 +84,7 @@ if ($response !== false) { break; } if ($what !== '') { - shell_exec(sprintf("echo Morgen %s abgeholt | %s -u %d", $what, $pathToBot, $tgReceiverId)); + shell_exec(sprintf("echo Morgen %s abgeholt | %s -u %d", $what, $config['pathBot'], $config['tgReceiver'])); } } }