Skip to content

Commit

Permalink
Merge pull request #201 from akrherz/afos_links
Browse files Browse the repository at this point in the history
feat: add more links to AFOS response
  • Loading branch information
akrherz committed May 31, 2024
2 parents e30b004 + f15bda5 commit 477c54f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/iemws/models/afos/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class AFOSListItem(BaseModel):
"""Data Schema."""

entered: str = Field(..., title="WMO Text Product Issuance Time (UTC)")
link: str = Field(
...,
title="URL to the IEM webpage showing this product.",
)
text_link: str = Field(
...,
title="URL to the raw text of the product.",
)
pil: str = Field(
...,
title="3-6 letter PIL with trailing whitespace trimmed.",
Expand Down
18 changes: 13 additions & 5 deletions src/iemws/services/nws/afos/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@

import datetime

from fastapi import APIRouter, HTTPException, Query

# Third Party
from pandas.io.sql import read_sql
from pyiem.util import get_sqlalchemy_conn, utc
import pandas as pd
from fastapi import APIRouter, HTTPException, Query
from pyiem.database import get_sqlalchemy_conn
from pyiem.util import utc
from sqlalchemy import text

# Local
Expand Down Expand Up @@ -78,7 +78,7 @@ def handler(cccc, pil, date):
fs.append("source = :cccc")
with get_sqlalchemy_conn("afos") as conn:
# We don't auto-list some internal products like WRK LLL
df = read_sql(
df = pd.read_sql(
text(
f"""
select entered at time zone 'UTC' as entered, trim(pil) as pil,
Expand All @@ -96,6 +96,14 @@ def handler(cccc, pil, date):
params=params,
index_col=None,
)
if not df.empty:
df["link"] = (
"https://mesonet.agron.iastate.edu/p.php?pid=" + df["product_id"]
)
df["text_link"] = (
"https://mesonet.agron.iastate.edu/api/1/nwstext/"
+ df["product_id"]
)
return df


Expand Down
4 changes: 2 additions & 2 deletions tests/nws/afos/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

def test_char3_source():
"""Test that we can deal with a 3 char source."""
req = client.get("/nws/afos/list.json?cccc=DMX&date=2022-10-24")
req = client.get("/nws/afos/list.json?cccc=DMX&date=2021-01-01")
res = req.json()
assert res is not None
assert len(res["data"]) >= 2


def test_badcall():
Expand Down

0 comments on commit 477c54f

Please sign in to comment.