doti3/bar/src/meteo.php
2022-09-26 12:11:24 +02:00

39 lines
924 B
PHP
Executable file

#!/usr/bin/env php
<?php
require __DIR__.'/base/block.php';
$url = 'https://fr.wttr.in/'.($argv[1] ?? '').'?format=%l+%c+%t+%m';
$command = sprintf('curl %s', escapeshellarg($url));
$output = trim(shell_exec($command));
if (!empty($output)) {
if (preg_match('/Unknow location/', $output)) {
$output = 'Météo HS';
}
if (preg_match('/mesure de faire de nouvelles/', $output)) {
$output = 'Météo HS';
}
try {
$city = explode(', ', $output)[0];
echo block(
'meteo',
[
'full_text' => pspan(preg_replace("/\s{2,}/", ' ', $output), '#fff'),
]
);
} catch(\Exception $e) {
}
}
if (getenv('BLOCK_BUTTON') === '1') {
// $url = 'https://fr.wttr.in/';
// $command = sprintf('xdg-open %s', escapeshellarg($url));
$command = 'gnome-weather --class="gnome-weather"&';
shell_exec($command);
}