mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 14:27:42 +00:00
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import csv
|
|
|
|
from core.enums import SIGRefType
|
|
from data.sig_ref import SIGRef
|
|
from providers.sigrefdata.local_file_sig_ref_data_provider import (
|
|
LocalFileSIGRefDataProvider,
|
|
)
|
|
|
|
|
|
class Toilets(LocalFileSIGRefDataProvider):
|
|
"""SIG ref data provider for Toilets on the Air"""
|
|
|
|
SIG = "Toilets"
|
|
PATH = "datafiles/toilets.csv"
|
|
|
|
def __init__(self, provider_config):
|
|
super().__init__(self.SIG, provider_config, self.PATH)
|
|
|
|
def _file_to_data(self, path):
|
|
new_data = []
|
|
with open(path) as _f:
|
|
csv_data = _f.read()
|
|
dr = csv.DictReader(csv_data.splitlines())
|
|
for row in dr:
|
|
new_data.append(
|
|
SIGRef(
|
|
sig=self.SIG,
|
|
id=row["ref"],
|
|
name=row["ref"],
|
|
ref_type=SIGRefType.TOILET,
|
|
latitude=float(row["lat"]),
|
|
longitude=float(row["lon"]),
|
|
)
|
|
)
|
|
|
|
# Bail out if a stop has been requested, i.e. the program is shutting down - no need to parse the rest
|
|
# of the data in this case
|
|
if self._stop_event.is_set():
|
|
break
|
|
|
|
return new_data
|