Skip to content

Commit

Permalink
NOAA scrape multiline extract
Browse files Browse the repository at this point in the history
  • Loading branch information
devdupont committed Oct 24, 2023
1 parent b708675 commit 4195866
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions avwx/service/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class _NOAA_ScrapeURL:

def _make_url(self, station: str, **kwargs: Union[int, str]) -> Tuple[str, dict]:
"""Returns a formatted URL and parameters"""
hours = 7 if self.report_type == "taf" else 2
hours = 24 if self.report_type == "taf" else 2
params = {"ids": station, "format": "raw", "hours": hours, **kwargs}
return self._url.format(self.report_type), params

Expand All @@ -156,8 +156,14 @@ class NOAA_Scrape(_NOAA_ScrapeURL, StationScrape):
"""Requests data from NOAA via response scraping"""

def _extract(self, raw: str, station: str) -> str:
"""Extracts the report using string finding"""
return raw.strip().split("\n")[0]
"""Extracts the first report"""
report = ""
for line in raw.strip().split("\n"):
# Break when seeing the second non-indented line (next report)
if line and line[0].isalnum() and report:
break
report += line
return report


class NOAA_ScrapeList(_NOAA_ScrapeURL, ScrapeService):
Expand Down

0 comments on commit 4195866

Please sign in to comment.