doti3/bar/src/meteo.php

39 lines
924 B
PHP
Raw Permalink Normal View History

2021-03-03 21:31:06 +01:00
#!/usr/bin/env php
2020-01-14 11:35:34 +01:00
<?php
require __DIR__.'/base/block.php';
2022-09-26 12:11:24 +02:00
$url = 'https://fr.wttr.in/'.($argv[1] ?? '').'?format=%l+%c+%t+%m';
2020-01-14 11:35:34 +01:00
$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',
[
2022-09-26 12:11:24 +02:00
'full_text' => pspan(preg_replace("/\s{2,}/", ' ', $output), '#fff'),
2020-01-14 11:35:34 +01:00
]
);
} catch(\Exception $e) {
}
}
if (getenv('BLOCK_BUTTON') === '1') {
2021-03-03 21:31:06 +01:00
// $url = 'https://fr.wttr.in/';
// $command = sprintf('xdg-open %s', escapeshellarg($url));
$command = 'gnome-weather --class="gnome-weather"&';
2020-01-14 11:35:34 +01:00
shell_exec($command);
}