Skip to content

Commit

Permalink
fetch goes metadata, use that to build gif url
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-does-weather committed Jul 30, 2024
1 parent 4934af6 commit 23e80ef
Show file tree
Hide file tree
Showing 6 changed files with 609 additions and 1 deletion.
21 changes: 21 additions & 0 deletions web/modules/weather_blocks/weather_blocks.module
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ function weather_blocks_template_preprocess_default_variables_alter(
}
} catch (Throwable $e) {
}

try {
$wfo = strtolower($weatherMetadata["grid"]->wfo);
$satellite = $weatherData->getSatelliteMetadata($wfo);

$goes = "GOES16";
$satellite = $satellite->meta->satellite;
if ($satellite == "GOES-West") {
$goes = "GOES18";
}

if ($satellite) {
$weatherMetadata["satellite"] = [
"gif" =>
"https://cdn.star.nesdis.noaa.gov/WFO/$wfo/GEOCOLOR/$goes-" .
strtoupper($wfo) .
"-GEOCOLOR-600x600.gif",
];
}
} catch (Throwable $e) {
}
}

$variables["weather"] = $weatherMetadata;
Expand Down
11 changes: 11 additions & 0 deletions web/modules/weather_data/src/Service/DataLayer.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,17 @@ public function getPlaceNearPolygon($points)
return self::$i_placeNearPolygon[$wktPoints];
}

public function getSatelliteMetadata($wfo)
{
$wfo = strtolower($wfo);
$url =
"https://cdn.star.nesdis.noaa.gov/WFO/catalogs/WFO_02_" .
$wfo .
"_catalog.json";
$response = $this->fetch($url)->wait();
return $response;
}

public function databaseFetch($sql)
{
return $this->database->query($sql)->fetch();
Expand Down
32 changes: 32 additions & 0 deletions web/modules/weather_data/src/Service/Test/DataLayer.php.test
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,36 @@ final class DataLayerTest extends TestCase

$this->assertEquals($expected, $actual);
}

/**
* @group unit
* @group data-layer
*/
public function testGetSatelliteMetadata(): void
{
$expected = (object) [
"satellite" => "is got",
];

$dataLayer = $this->getDataLayer(false);
$this->httpClient->append(
new Response(
200,
["Content-type", "application/json"],
json_encode($expected),
),
);

$actual = $dataLayer->getSatelliteMetadata("BOB");

$this->assertEquals($expected, $actual);
$this->assertEquals(
"GET",
$this->httpHistory[0]["request"]->getMethod(),
);
$this->assertEquals(
"/WFO/catalogs/WFO_02_bob_catalog.json",
$this->httpHistory[0]["request"]->getURI()->getPath(),
);
}
}
Loading

0 comments on commit 23e80ef

Please sign in to comment.