mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 22:37:44 +00:00
Add support for WA7BNM Contest Calendar. Closes #106
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
from icalendar import Event
|
||||
|
||||
from core.enums import AlertType
|
||||
from data.alert import Alert
|
||||
from providers.alert.ical_alert_provider import ICALAlertProvider
|
||||
|
||||
|
||||
class WA7BNM(ICALAlertProvider):
|
||||
"""Alert provider for the WA7BNM contest calendar."""
|
||||
|
||||
POLL_INTERVAL_DAYS = 1
|
||||
ALERTS_URL = "https://contestcalendar.com/weeklycontcustom.php"
|
||||
|
||||
def __init__(self, provider_config):
|
||||
super().__init__(
|
||||
"WA7BNM Contest Calendar", provider_config, self.ALERTS_URL, self.POLL_INTERVAL_DAYS * 24 * 60 * 60
|
||||
)
|
||||
|
||||
def event_to_alert(self, event: Event) -> Alert:
|
||||
"""Convert an iCal event in WA7BNM's format to an Alert object."""
|
||||
|
||||
summary = str(event.get("summary", ""))
|
||||
url = str(event.get("url", ""))
|
||||
|
||||
dtstart = event.get("dtstart")
|
||||
dtend = event.get("dtend")
|
||||
start_timestamp = self._to_utc_timestamp(dtstart.dt)
|
||||
end_timestamp = self._to_utc_timestamp(dtend.dt) - 1 if dtend is not None else start_timestamp
|
||||
|
||||
# Convert to our alert format
|
||||
alert = Alert(
|
||||
source=self.name,
|
||||
dx_calls=[],
|
||||
comment=summary,
|
||||
url=url,
|
||||
start_time=start_timestamp,
|
||||
end_time=end_timestamp,
|
||||
alert_type=AlertType.CONTEST,
|
||||
)
|
||||
|
||||
return alert
|
||||
Reference in New Issue
Block a user