diff --git a/scripts/import/import_tcrb.php b/scripts/import/import_tcrb.php index 0fd3a69..68fde09 100644 --- a/scripts/import/import_tcrb.php +++ b/scripts/import/import_tcrb.php @@ -626,6 +626,11 @@ function parseWebObsPage(string $html): array } } + $magnitude = parseStrictDecimal($magnitudeText); + if ($magnitude === null) { + continue; + } + $jd = (float) str_replace(',', '.', $jdText); $observedAtUtc = jdToUtcString($jd); @@ -635,8 +640,8 @@ function parseWebObsPage(string $html): array 'jd' => number_format($jd, 6, '.', ''), 'observed_at_utc' => $observedAtUtc, 'calendar_date_text' => $calendarDateText !== '' ? $calendarDateText : null, - 'magnitude' => normalizeNumeric($magnitudeText), - 'magnitude_error' => $magnitudeErrorText !== '' ? normalizeNumeric($magnitudeErrorText) : null, + 'magnitude' => $magnitude, + 'magnitude_error' => $magnitudeErrorText !== '' ? parseStrictDecimal($magnitudeErrorText) : null, 'filter_code' => $filterCode !== '' ? $filterCode : null, 'observer_code' => $observerCode !== '' ? $observerCode : null, 'notes_raw' => $notesRaw, @@ -662,6 +667,20 @@ function normalizeNumeric(string $value): string return str_replace(',', '.', trim($value)); } +function parseStrictDecimal(string $value): ?string +{ + $normalized = normalizeNumeric($value); + if ($normalized === '') { + return null; + } + + if (preg_match('/^[+-]?\d+(?:\.\d+)?$/', $normalized) !== 1) { + return null; + } + + return $normalized; +} + function jdToUtcString(float $jd): string { $jd += 0.5; diff --git a/scripts/telegram/lib/tcrb_helpers.php b/scripts/telegram/lib/tcrb_helpers.php index 1114acd..a2fb7b8 100644 --- a/scripts/telegram/lib/tcrb_helpers.php +++ b/scripts/telegram/lib/tcrb_helpers.php @@ -108,7 +108,7 @@ function buildTcrbLatestVMessage(array $observation, DateTimeImmutable $nowBerli $observedText = formatGermanDateTime($observedUtc); $magnitude = formatDecimal($observation['magnitude'] ?? null, 3); $magnitudeError = $observation['magnitude_error'] !== null - ? ' ± ' . formatDecimal($observation['magnitude_error'], 3) + ? ' ± ' . formatDecimal($observation['magnitude_error'], 3) : ''; $jd = formatDecimal($observation['jd'] ?? null, 6); $observerCode = trim((string) ($observation['observer_code'] ?? '')); @@ -120,7 +120,7 @@ function buildTcrbLatestVMessage(array $observation, DateTimeImmutable $nowBerli 'Magnitude: ' . $magnitude . $magnitudeError, 'Zeitpunkt: ' . $observedText, 'JD: ' . $jd, - 'Nächster möglicher Ausbruch: '. $nextPossibleEruptionDate, + 'Nächster möglicher Ausbruch: ' . $nextPossibleEruptionDate, ]; diff --git a/scripts/telegram/lib/telegram_api.php b/scripts/telegram/lib/telegram_api.php index 315a90b..c15ba05 100644 --- a/scripts/telegram/lib/telegram_api.php +++ b/scripts/telegram/lib/telegram_api.php @@ -9,7 +9,7 @@ declare(strict_types=1); * und Dokumenten. Die Cron-Tasks muessen dadurch keine Request-Details kennen. */ -require_once dirname(__DIR__, 2) . '/public/telegram/lib/http.php'; +require_once dirname(__DIR__, 3) . '/public/telegram/lib/http.php'; function telegramHttpPostMultipart(string $url, array $fields, string $fileField, string $filePath, ?string $fileName = null): array