england.GovAlert

This commit is contained in:
SpudGunMan
2024-12-18 19:33:11 -08:00
parent 6974c4ef66
commit 454f823ad7
4 changed files with 18 additions and 10 deletions
+12 -7
View File
@@ -12,14 +12,19 @@ from modules.log import *
trap_list_location_eu = ("ukalert", "ukwx", "ukflood")
def get_govUK_alerts():
# get UK weather alerts
url = 'https://www.gov.uk/alerts'
response = requests.get(url)
soup = bs.BeautifulSoup(response.text, 'html.parser')
# the alerts are in <h2 class="govuk-heading-m" id="alert-status">
alert = soup.find('h2', class_='govuk-heading-m', id='alert-status')
try:
# get UK.gov alerts
url = 'https://www.gov.uk/alerts'
response = requests.get(url)
soup = bs.BeautifulSoup(response.text, 'html.parser')
# the alerts are in <h2 class="govuk-heading-m" id="alert-status">
alert = soup.find('h2', class_='govuk-heading-m', id='alert-status')
except Exception as e:
logger.warning("Error getting UK alerts: " + str(e))
return "System: Error getting UK alerts"
if alert:
return alert.get_text(strip=True)
return "🚨" + alert.get_text(strip=True)
else:
return "No alerts"