mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2025-12-15 16:43:38 +00:00
Fix WOTA parsing bug
This commit is contained in:
@@ -4,7 +4,7 @@ from data.sig import SIG
|
|||||||
|
|
||||||
# General software
|
# General software
|
||||||
SOFTWARE_NAME = "Spothole by M0TRT"
|
SOFTWARE_NAME = "Spothole by M0TRT"
|
||||||
SOFTWARE_VERSION = "1.0"
|
SOFTWARE_VERSION = "1.0.1"
|
||||||
|
|
||||||
# HTTP headers used for spot providers that use HTTP
|
# HTTP headers used for spot providers that use HTTP
|
||||||
HTTP_HEADERS = {"User-Agent": SOFTWARE_NAME + ", v" + SOFTWARE_VERSION + " (operated by " + SERVER_OWNER_CALLSIGN + ")"}
|
HTTP_HEADERS = {"User-Agent": SOFTWARE_NAME + ", v" + SOFTWARE_VERSION + " (operated by " + SERVER_OWNER_CALLSIGN + ")"}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import logging
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
from rss_parser import RSSParser
|
from rss_parser import RSSParser
|
||||||
|
|
||||||
from core.sig_utils import get_icon_for_sig
|
|
||||||
from data.sig_ref import SIGRef
|
from data.sig_ref import SIGRef
|
||||||
from data.spot import Spot
|
from data.spot import Spot
|
||||||
from spotproviders.http_spot_provider import HTTPSpotProvider
|
from spotproviders.http_spot_provider import HTTPSpotProvider
|
||||||
@@ -12,7 +13,7 @@ from spotproviders.http_spot_provider import HTTPSpotProvider
|
|||||||
# Spot provider for Wainwrights on the Air
|
# Spot provider for Wainwrights on the Air
|
||||||
class WOTA(HTTPSpotProvider):
|
class WOTA(HTTPSpotProvider):
|
||||||
POLL_INTERVAL_SEC = 120
|
POLL_INTERVAL_SEC = 120
|
||||||
SPOTS_URL = "https://www.wota.org.uk/spots_rss.php"
|
SPOTS_URL = "http://127.0.0.1:8000/spots_rss.php"
|
||||||
LIST_URL = "https://www.wota.org.uk/mapping/data/summits.json"
|
LIST_URL = "https://www.wota.org.uk/mapping/data/summits.json"
|
||||||
RSS_DATE_TIME_FORMAT = "%a, %d %b %Y %H:%M:%S %z"
|
RSS_DATE_TIME_FORMAT = "%a, %d %b %Y %H:%M:%S %z"
|
||||||
|
|
||||||
@@ -25,47 +26,50 @@ class WOTA(HTTPSpotProvider):
|
|||||||
# Iterate through source data
|
# Iterate through source data
|
||||||
for source_spot in rss.channel.items:
|
for source_spot in rss.channel.items:
|
||||||
|
|
||||||
# Reject GUID missing or zero
|
try:
|
||||||
if not source_spot.guid or not source_spot.guid.content or source_spot.guid.content == "http://www.wota.org.uk/spots/0":
|
# Reject GUID missing or zero
|
||||||
continue
|
if not source_spot.guid or not source_spot.guid.content or source_spot.guid.content == "http://www.wota.org.uk/spots/0":
|
||||||
|
continue
|
||||||
|
|
||||||
# Pick apart the title
|
# Pick apart the title
|
||||||
title_split = source_spot.title.split(" on ")
|
title_split = source_spot.title.split(" on ")
|
||||||
dx_call = title_split[0]
|
dx_call = title_split[0]
|
||||||
ref = None
|
ref = None
|
||||||
ref_name = None
|
ref_name = None
|
||||||
if len(title_split) > 1:
|
if len(title_split) > 1:
|
||||||
ref_split = title_split[1].split(" - ")
|
ref_split = title_split[1].split(" - ")
|
||||||
ref = ref_split[0]
|
ref = ref_split[0]
|
||||||
if len(ref_split) > 1:
|
if len(ref_split) > 1:
|
||||||
ref_name = ref_split[1]
|
ref_name = ref_split[1]
|
||||||
|
|
||||||
# Pick apart the description
|
# Pick apart the description
|
||||||
desc_split = source_spot.description.split(". ")
|
desc_split = source_spot.description.split(". ")
|
||||||
freq_mode = desc_split[0].replace("Frequencies/modes:", "").strip()
|
freq_mode = desc_split[0].replace("Frequencies/modes:", "").strip()
|
||||||
freq_mode_split = freq_mode.split("-")
|
freq_mode_split = re.split(r'[\-\s]+', freq_mode)
|
||||||
freq_hz = float(freq_mode_split[0]) * 1000000
|
freq_hz = float(freq_mode_split[0]) * 1000000
|
||||||
mode = freq_mode_split[1]
|
mode = freq_mode_split[1].upper()
|
||||||
|
|
||||||
comment = None
|
comment = None
|
||||||
if len(desc_split) > 1:
|
if len(desc_split) > 1:
|
||||||
comment = desc_split[1].strip()
|
comment = desc_split[1].strip()
|
||||||
spotter = None
|
spotter = None
|
||||||
if len(desc_split) > 2:
|
if len(desc_split) > 2:
|
||||||
spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").strip()
|
spotter = desc_split[2].replace("Spotted by ", "").replace(".", "").upper().strip()
|
||||||
|
|
||||||
time = datetime.strptime(source_spot.pub_date.content, self.RSS_DATE_TIME_FORMAT).astimezone(pytz.UTC)
|
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.guid.content,
|
source_id=source_spot.guid.content,
|
||||||
dx_call=dx_call,
|
dx_call=dx_call,
|
||||||
de_call=spotter,
|
de_call=spotter,
|
||||||
freq=freq_hz,
|
freq=freq_hz,
|
||||||
mode=mode,
|
mode=mode,
|
||||||
comment=comment,
|
comment=comment,
|
||||||
sig_refs=[SIGRef(id=ref, sig="WOTA", name=ref_name)] if ref else [],
|
sig_refs=[SIGRef(id=ref, sig="WOTA", name=ref_name)] if ref else [],
|
||||||
time=time.timestamp())
|
time=time.timestamp())
|
||||||
|
|
||||||
new_spots.append(spot)
|
new_spots.append(spot)
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Exception parsing WOTA spot", e)
|
||||||
return new_spots
|
return new_spots
|
||||||
|
|||||||
Reference in New Issue
Block a user