Skip to content

Commit

Permalink
v8.0.0-beta4 fixed url handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ampledata committed Jun 24, 2024
1 parent d1d9b0c commit 335a6c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion adsbcot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

"""ADS-B to TAK Gateway."""

__version__ = "8.0.0-beta3"
__version__ = "8.0.0-beta4"

# COMPAT Python 3.6 test/build work-around:
try:
Expand Down
29 changes: 17 additions & 12 deletions adsbcot/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,7 @@ async def get_feed(self, url: bytes) -> None:

async def run(self, _=-1) -> None:
"""Run this Thread, Reads from Pollers."""
dump1090_url: bytes = self.config.get("DUMP1090_URL", "")
if dump1090_url:
warnings.warn(
"DUMP1090_URL setting is DEPRECATED. Please use FEED_URL instead."
)

url: bytes = self.config.get("FEED_URL", dump1090_url)
url: bytes = self.config.get("FEED_URL")
if not url:
raise ValueError("Please specify a FEED_URL.")

Expand Down Expand Up @@ -199,7 +193,7 @@ async def run(self, _=-1) -> None:
self._logger.info(
"%s polling every %ss: %s", self.__class__, poll_interval, url
)
await self.get_file_feed(url)
await self.get_file_feed(feed_url)
await asyncio.sleep(int(poll_interval))
else:
with Inotify() as inotify:
Expand All @@ -213,14 +207,25 @@ async def run(self, _=-1) -> None:
if str(event.path) == path:
await self.get_file_feed(feed_url)

async def get_file_feed(self, feed_url) -> None:
async def get_file_feed(self, feed_url: ParseResultBytes) -> None:
"""Read data from an aircraft JSON file."""
jdata = {}
jdata: dict = {}
feed_data: str = ""

with open(feed_url.path, "r", encoding="UTF-8") as feed_fd:
jdata = json.loads(feed_fd.read())
feed_data = feed_fd.read()

if not feed_data:
self._logger.info("No data returned from FEED_URL=%s", feed_url.path)
return

jdata = json.loads(feed_data)

data = jdata.get("aircraft", jdata.get("ac"))
if data is None:
if not data:
self._logger.info(
"No aircraft data returned from FEED_URL=%s", feed_url.path
)
return

self._logger.info(
Expand Down

0 comments on commit 335a6c6

Please sign in to comment.