add meteo

This commit is contained in:
Simon Vieille 2020-01-14 11:35:34 +01:00
parent fcc31cdba8
commit 5786e6841c
Signed by: deblan
GPG Key ID: 03383D15A1D31745
1 changed files with 37 additions and 0 deletions

37
bar/src/meteo.php Executable file
View File

@ -0,0 +1,37 @@
#!/usr/bin/php7.1
<?php
require __DIR__.'/base/block.php';
$url = 'https://fr.wttr.in/?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($output, '#fff'),
]
);
} catch(\Exception $e) {
}
}
if (getenv('BLOCK_BUTTON') === '1') {
$url = 'https://fr.wttr.in/';
$command = sprintf('xdg-open %s', escapeshellarg($url));
shell_exec($command);
}