43 lines
1.1 KiB
PHP
43 lines
1.1 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
header('User-Agent: worldsphere.ai, contact@worldsphere.ai');
|
|
|
|
// URL for the SPC RSS feed
|
|
$url = 'http://www.spc.noaa.gov/products/spcrss.xml';
|
|
|
|
// Fetch the RSS feed content
|
|
$rss = @file_get_contents($url);
|
|
|
|
if ($rss === false) {
|
|
echo json_encode(['error' => 'Failed to fetch SPC data.']);
|
|
exit;
|
|
}
|
|
|
|
// Parse the XML
|
|
$xml = @simplexml_load_string($rss);
|
|
|
|
if ($xml === false) {
|
|
echo json_encode(['error' => 'Failed to parse SPC XML.']);
|
|
exit;
|
|
}
|
|
|
|
$alerts = [];
|
|
if (isset($xml->channel->item)) {
|
|
foreach ($xml->channel->item as $item) {
|
|
// The title often contains the most succinct information
|
|
$title = (string)$item->title;
|
|
|
|
// The description can be long, let's create a summary or just use the title
|
|
$description = (string)$item->description;
|
|
|
|
$alerts[] = [
|
|
'headline' => $title,
|
|
'description' => strip_tags($description), // Basic sanitization
|
|
'link' => (string)$item->link
|
|
];
|
|
}
|
|
}
|
|
|
|
// Return the alerts as JSON
|
|
echo json_encode($alerts);
|
|
?>
|