muell.php gelöscht, da veraltet
This commit is contained in:
parent
45cdf3859c
commit
6fdbc75104
109
php/muell.php
109
php/muell.php
@ -1,109 +0,0 @@
|
||||
#!/usr/bin/php
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Um die Werte für kommune und strasse zu erfahren, rufe https://www.egst.de/de/abfallabholung/ per
|
||||
* Browser auf und ermittle die gesendeten Daten in der Entwicklerkonsole deines Browsers.
|
||||
*
|
||||
* 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/Programm schreiben, dass die API
|
||||
* von Telegram verwendet und Daten an dich oder deine Gruppe senden kann!
|
||||
*
|
||||
* Beispiel für eine Konfigurationsdatei:
|
||||
* tgReceiver: <hier die ID der Gruppe/ des Teilnhemers eintragen>
|
||||
* kommune: 2601
|
||||
* strasse: 2146
|
||||
* pathBot: '~/bin/YMBot'
|
||||
* tgBotOwner: <hier DEINE Telegram-ID eintragen>
|
||||
*/
|
||||
|
||||
function worker(string $response, array $config)
|
||||
{
|
||||
$tomorrow = (new DateTime('tomorrow'))->format('d.m.Y');
|
||||
$trashArr = str_getcsv($response, "\n");
|
||||
|
||||
foreach($trashArr as $row) {
|
||||
$rowArr = str_getcsv($row, ';');
|
||||
$index = array_search($tomorrow, $rowArr);
|
||||
if ($index !== false) {
|
||||
$what = '';
|
||||
switch ($index) {
|
||||
case 0:
|
||||
case 1:
|
||||
$what = "werden Biomüll und gelbe Tonne";
|
||||
break;
|
||||
case 2:
|
||||
$what = "wird Restmüll";
|
||||
break;
|
||||
case 3:
|
||||
$what = "wird Papier";
|
||||
break;
|
||||
}
|
||||
if ($what !== '') {
|
||||
shell_exec(sprintf("echo Morgen %s abgeholt | %s -u %d", $what, $config['pathBot'], $config['tgReceiver']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Main part
|
||||
$currentYear = date('Y');
|
||||
$dateRange = sprintf('%s0101-%s1231', $currentYear, $currentYear);
|
||||
$muellFile = sprintf('%s/muell.csv', __DIR__);
|
||||
|
||||
$key = 'e21758b9c711463552fb9c70ac7d4273';
|
||||
|
||||
$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' => $config['kommune'],
|
||||
'f_id_strasse' => $config['strasse'],
|
||||
'f_id_abfalltyp_0' => 50,
|
||||
'f_id_abfalltyp_1' => 161,
|
||||
'f_id_abfalltyp_2' => 53,
|
||||
'f_id_abfalltyp_3' => 187,
|
||||
'f_abfallarten_index_max' => 5,
|
||||
'f_abfallarten' => '50,161,53,187',
|
||||
'f_zeitraum' => $dateRange,
|
||||
'f_export_als' => json_encode([
|
||||
'action' => $url,
|
||||
'target' => '',
|
||||
]),
|
||||
];
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0');
|
||||
|
||||
$response = curl_exec($ch)."\n";
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($response !== false) {
|
||||
// If result file does not exist, write it to have a copy
|
||||
file_put_contents($muellFile, $response);
|
||||
|
||||
// Go on with checking the result data
|
||||
worker($response, $config);
|
||||
} else {
|
||||
if (file_exists($muellFile)) {
|
||||
worker(file_get_contents($muellFile), $config);
|
||||
} else {
|
||||
shell_exec(sprintf("echo Müllbot konnte keine Daten empfangen | %s -u %d", $config['pathBot'], $config['tgBotOwner']));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user