Skip to content

Commit 8c44959

Browse files
authored
Merge pull request #1184 from akrherz/website_telem
Improve website_telemetry write
2 parents a660f66 + 88f572d commit 8c44959

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ ci:
22
autoupdate_schedule: quarterly
33
repos:
44
- repo: https://github.com/astral-sh/ruff-pre-commit
5-
rev: "v0.15.6"
5+
rev: "v0.15.7"
66
hooks:
77
- id: ruff-check
88
args: [--fix, --exit-non-zero-on-fix]
99
- id: ruff-format
1010

1111
- repo: https://github.com/tox-dev/pyproject-fmt
12-
rev: 'v2.19.0'
12+
rev: 'v2.20.0'
1313
hooks:
1414
- id: pyproject-fmt

src/pyiem/plot/geoplot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ def draw_usdm(self, valid=None, filled=True, hatched=False, **kwargs):
289289
"""
290290
colors = ["#ffff00", "#fcd37f", "#ffaa00", "#e60000", "#730000"]
291291
hatches = ["+", "/", "\\", "-", "x"]
292-
if valid is None:
293-
valid = ""
294-
elif isinstance(valid, (datetime.date, datetime.datetime)):
292+
params = {}
293+
if isinstance(valid, (datetime.date, datetime.datetime)):
295294
valid = valid.strftime("%Y-%m-%d")
296-
url = f"http://mesonet.agron.iastate.edu/geojson/usdm.py?date={valid}"
295+
params["date"] = valid
296+
url = "http://mesonet.agron.iastate.edu/geojson/usdm.py"
297297
try:
298-
resp = httpx.get(url, timeout=30)
298+
resp = httpx.get(url, params=params, timeout=30)
299299
resp.raise_for_status()
300300
df = gpd.GeoDataFrame().from_features(resp.json())
301301
except Exception as exp:

src/pyiem/webutil.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def write_telemetry(data: TELEMETRY) -> bool:
191191
"""Write telemetry to the database."""
192192
# Yes, this blocks, but if this database is not working, we are in trouble
193193
try:
194-
with get_sqlalchemy_conn("mesosite") as conn:
194+
with get_sqlalchemy_conn("mesosite", rw=True) as conn:
195195
conn.execute(
196196
sql_helper(
197197
"""
@@ -205,6 +205,9 @@ def write_telemetry(data: TELEMETRY) -> bool:
205205
)
206206
conn.commit()
207207
return True
208+
except NewDatabaseConnectionFailure:
209+
# swallow this
210+
return False
208211
except Exception as exp:
209212
LOG.exception(exp)
210213
return False

tests/plot/test_geoplot.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,9 @@ def test_overlay_nexrad_failure():
4949
def test_exercise_usdm():
5050
"""Test the various checks in the usdm method."""
5151
mp = MapPlot()
52-
with pytest.warns(UserWarning) as _:
53-
mp.draw_usdm()
5452
mp.draw_usdm(utc())
5553
with pytest.warns(UserWarning) as _:
56-
assert mp.draw_usdm("qqq") is None
57-
assert mp.draw_usdm(utc(1980, 1, 1)) is None
54+
assert mp.draw_usdm(utc(1980, 1, 1)) is None
5855

5956

6057
def test_close():

0 commit comments

Comments
 (0)