mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-10-27 00:39:26 +00:00
Finish support for WOTA #63
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import re
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
@@ -23,6 +22,11 @@ class WOTA(HTTPAlertProvider):
|
|||||||
rss = RSSParser.parse(http_response.content.decode())
|
rss = RSSParser.parse(http_response.content.decode())
|
||||||
# Iterate through source data
|
# Iterate through source data
|
||||||
for source_alert in rss.channel.items:
|
for source_alert in rss.channel.items:
|
||||||
|
|
||||||
|
# Reject GUID missing or zero
|
||||||
|
if not source_alert.guid or not source_alert.guid.content or source_alert.guid.content == "http://www.wota.org.uk/alerts/0":
|
||||||
|
continue
|
||||||
|
|
||||||
# Pick apart the title
|
# Pick apart the title
|
||||||
title_split = source_alert.title.split(" on ")
|
title_split = source_alert.title.split(" on ")
|
||||||
dx_call = title_split[0]
|
dx_call = title_split[0]
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import re
|
from datetime import timedelta, datetime
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
|
import pytz
|
||||||
from requests_cache import CachedSession
|
from requests_cache import CachedSession
|
||||||
from rss_parser import RSSParser
|
from rss_parser import RSSParser
|
||||||
|
|
||||||
from core.constants import HTTP_HEADERS
|
from core.constants import HTTP_HEADERS
|
||||||
|
from core.sig_utils import get_icon_for_sig
|
||||||
from data.spot import Spot
|
from data.spot import Spot
|
||||||
from spotproviders.http_spot_provider import HTTPSpotProvider
|
from spotproviders.http_spot_provider import HTTPSpotProvider
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ class WOTA(HTTPSpotProvider):
|
|||||||
LIST_URL = "https://www.wota.org.uk/mapping/data/summits.json"
|
LIST_URL = "https://www.wota.org.uk/mapping/data/summits.json"
|
||||||
LIST_CACHE_TIME_DAYS = 30
|
LIST_CACHE_TIME_DAYS = 30
|
||||||
LIST_CACHE = CachedSession("cache/wota_data_cache", expire_after=timedelta(days=LIST_CACHE_TIME_DAYS))
|
LIST_CACHE = CachedSession("cache/wota_data_cache", expire_after=timedelta(days=LIST_CACHE_TIME_DAYS))
|
||||||
|
RSS_DATE_TIME_FORMAT = "%a, %d %b %Y %H:%M:%S %z"
|
||||||
|
|
||||||
def __init__(self, provider_config):
|
def __init__(self, provider_config):
|
||||||
super().__init__(provider_config, self.SPOTS_URL, self.POLL_INTERVAL_SEC)
|
super().__init__(provider_config, self.SPOTS_URL, self.POLL_INTERVAL_SEC)
|
||||||
@@ -24,22 +26,53 @@ class WOTA(HTTPSpotProvider):
|
|||||||
new_spots = []
|
new_spots = []
|
||||||
rss = RSSParser.parse(http_response.content.decode())
|
rss = RSSParser.parse(http_response.content.decode())
|
||||||
# Iterate through source data
|
# Iterate through source data
|
||||||
for source_alert in rss.channel.items:
|
for source_spot in rss.channel.items:
|
||||||
break
|
|
||||||
# TODO: Need to see a live spot to know what this feed looks like
|
# Reject GUID missing or zero
|
||||||
|
if not source_spot.guid or not source_spot.guid.content or source_spot.guid.content == "http://www.wota.org.uk/alerts/0":
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Pick apart the title
|
||||||
|
title_split = source_spot.title.split(" on ")
|
||||||
|
dx_call = title_split[0]
|
||||||
|
ref = None
|
||||||
|
ref_name = None
|
||||||
|
if len(title_split) > 1:
|
||||||
|
ref_split = title_split[1].split(" - ")
|
||||||
|
ref = ref_split[0]
|
||||||
|
if len(ref_split) > 1:
|
||||||
|
ref_name = ref_split[1]
|
||||||
|
|
||||||
|
# Pick apart the description
|
||||||
|
desc_split = source_spot.description.split(". ")
|
||||||
|
freq_mode = desc_split[0].replace("Frequencies/modes:", "").strip()
|
||||||
|
freq_mode_split = freq_mode.split("-")
|
||||||
|
freq_hz = float(freq_mode_split[0]) * 1000000
|
||||||
|
mode = freq_mode_split[1]
|
||||||
|
|
||||||
|
comment = None
|
||||||
|
if len(desc_split) > 1:
|
||||||
|
comment = desc_split[1].strip()
|
||||||
|
spotter = None
|
||||||
|
if len(desc_split) > 2:
|
||||||
|
spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").strip()
|
||||||
|
|
||||||
|
time = datetime.strptime(source_spot.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC)
|
||||||
|
|
||||||
# Convert to our spot format
|
# Convert to our spot format
|
||||||
# spot = Spot(source=self.name,
|
spot = Spot(source=self.name,
|
||||||
# source_id=source_spot["id"],
|
source_id=source_spot.guid.content,
|
||||||
# dx_call=source_spot["activator"].upper(),
|
dx_call=dx_call,
|
||||||
# de_call=source_spot["spotter"].upper(),
|
de_call=spotter,
|
||||||
# freq=freq_hz,
|
freq=freq_hz,
|
||||||
# mode=source_spot["mode"].upper().strip(),
|
mode=mode,
|
||||||
# comment=source_spot["comments"],
|
comment=comment,
|
||||||
# sig="WOTA",
|
sig="WOTA",
|
||||||
# sig_refs=[source_spot["reference"]],
|
sig_refs=[ref] if ref else [],
|
||||||
# icon=get_icon_for_sig("WOTA"),
|
sig_refs_names=[ref_name] if ref_name else [],
|
||||||
# time=datetime.fromisoformat(source_spot["referenced_time"]).astimezone(pytz.UTC).timestamp())
|
sig_refs_urls="https://www.wota.org.uk/MM_" + ref if ref else [],
|
||||||
|
icon=get_icon_for_sig("WOTA"),
|
||||||
|
time=time.timestamp())
|
||||||
|
|
||||||
# WOTA name/lat/lon lookup
|
# WOTA name/lat/lon lookup
|
||||||
wota_data = self.LIST_CACHE.get(self.LIST_URL, headers=HTTP_HEADERS).json()
|
wota_data = self.LIST_CACHE.get(self.LIST_URL, headers=HTTP_HEADERS).json()
|
||||||
@@ -50,4 +83,6 @@ class WOTA(HTTPSpotProvider):
|
|||||||
spot.dx_longitude = feature["geometry"]["coordinates"][0]
|
spot.dx_longitude = feature["geometry"]["coordinates"][0]
|
||||||
spot.dx_grid = feature["properties"]["qthLocator"]
|
spot.dx_grid = feature["properties"]["qthLocator"]
|
||||||
break
|
break
|
||||||
|
|
||||||
|
new_spots.append(spot)
|
||||||
return new_spots
|
return new_spots
|
||||||
|
|||||||
Reference in New Issue
Block a user