Skip to content

Commit

Permalink
Merge pull request #1006 from akrherz/runner
Browse files Browse the repository at this point in the history
🎨 Map runner user to mesonet
  • Loading branch information
akrherz authored Jan 13, 2025
2 parents 23ea500 + d0956a0 commit 6e89d9f
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 35 deletions.
1 change: 1 addition & 0 deletions src/pyiem/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"apache": "nobody",
"www-data": "nobody",
"akrherz": "mesonet",
"runner": "mesonet", # github actions
"meteor_ldm": "ldm",
}

Expand Down
8 changes: 4 additions & 4 deletions src/pyiem/nws/products/cf6.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Parser for the CF6 Product."""

import calendar
import datetime
import re
from datetime import date, datetime, timedelta
from io import StringIO

import pandas as pd
Expand Down Expand Up @@ -78,7 +78,7 @@ def parser(self):
break
if year is None or month is None:
raise ValueError("Failed to find required month and year values")
day1 = datetime.datetime.strptime(
day1 = datetime.strptime(
f"{year} {month} 1",
"%Y %B %d" if len(month) > 3 else "%Y %b %d",
)
Expand All @@ -104,10 +104,10 @@ def parser(self):
continue
df[col] = pd.to_numeric(df[col], errors="coerce")
df["valid"] = df["dy"].apply(
lambda x: datetime.date(day1.year, day1.month, int(x))
lambda x: date(day1.year, day1.month, int(x))
)
# Ensure we don't have data from utcnow + 1 day
ceiling = (self.utcnow + datetime.timedelta(days=1)).date()
ceiling = (self.utcnow + timedelta(days=1)).date()
indicies = pd.to_datetime(df["valid"]) > pd.Timestamp(ceiling)
if indicies.any():
self.warnings.append(f"{indicies.sum()} rows from the future")
Expand Down
6 changes: 3 additions & 3 deletions src/pyiem/nws/products/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Parser and object storage of information within NWS CLI Product."""

import datetime
import re
from datetime import date, datetime

from pyiem.exceptions import CLIException
from pyiem.nws.product import TextProduct
Expand Down Expand Up @@ -152,7 +152,7 @@ def trace_r(val):
def get_number_year(text):
"""Ensure we get a year that makes sense."""
val = get_number(text)
if val is None or val < 1700 or val > (datetime.date.today().year + 1):
if val is None or val < 1700 or val > (date.today().year + 1):
return None
return val

Expand Down Expand Up @@ -341,7 +341,7 @@ def parse_headline(section):
"""Figure out when this product is valid for"""
tokens = HEADLINE_RE.findall(section.replace("\n", " "))
myfmt = "%b %d %Y" if len(tokens[0][2].split()[0]) == 3 else "%B %d %Y"
cli_valid = datetime.datetime.strptime(tokens[0][2], myfmt).date()
cli_valid = datetime.strptime(tokens[0][2], myfmt).date()
cli_station = (tokens[0][0]).strip().upper()
return (cli_valid, cli_station)

Expand Down
10 changes: 5 additions & 5 deletions src/pyiem/nws/products/ero.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
Weather Prediction Center Excessive Rainfall Outlook.
"""

import datetime
import math
import re
import tempfile
from datetime import datetime, timezone

from metpy.units import units
from shapely.geometry import MultiPolygon
Expand Down Expand Up @@ -353,14 +353,14 @@ def find_issue_expire(self):
else:
hour2 = int(m[4])
minute2 = 0
self.issue = datetime.datetime.strptime(
self.issue = datetime.strptime(
f"{hour1}:{minute1} {m[1]} {m[2]} {m[3]}",
"%H:%M %b %d %Y",
).replace(tzinfo=datetime.timezone.utc)
self.expire = datetime.datetime.strptime(
).replace(tzinfo=timezone.utc)
self.expire = datetime.strptime(
f"{hour2}:{minute2} {m[5]} {m[6]} {m[7]}",
"%H:%M %b %d %Y",
).replace(tzinfo=datetime.timezone.utc)
).replace(tzinfo=timezone.utc)

def find_outlooks(self):
"""Find the outlook sections within the text product!"""
Expand Down
6 changes: 3 additions & 3 deletions src/pyiem/nws/products/fd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Parser for the FD (Temp Wind Aloft Forecasts)."""

import datetime
import re
from datetime import timedelta

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -41,9 +41,9 @@ def compute_time(valid, tokens):
dd, hh, mi = int(tokens[0][:2]), int(tokens[0][2:4]), int(tokens[0][4:6])
valid2 = valid.replace(hour=hh, minute=mi)
if valid.day > 25 and dd < 5:
valid2 += datetime.timedelta(days=10)
valid2 += timedelta(days=10)
if valid.day < 5 and dd > 25:
valid2 -= datetime.timedelta(days=10)
valid2 -= timedelta(days=10)
valid2 = valid2.replace(day=dd)
# In theory, we should not be far apart
if abs((valid2 - valid).days) > 5:
Expand Down
10 changes: 5 additions & 5 deletions src/pyiem/nws/products/mos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
Supports parsing of Textual Model Output Statistics files
"""

import datetime
import re
from datetime import timedelta

from pyiem.util import utc
from pyiem.wmo import WMOProduct
Expand Down Expand Up @@ -46,14 +46,14 @@ def section_parser(sect):
hrs = lines[2].split()
for i, hr in enumerate(hrs[1:]):
if model == "LAV" and hrs[0] == "HR":
ts = initts + datetime.timedelta(hours=int(hr))
ts = initts + timedelta(hours=int(hr))
elif model == "LAV":
ts = initts + datetime.timedelta(hours=i + 1)
ts = initts + timedelta(hours=i + 1)
assert ts.hour == int(hr)
elif model in ["MEX", "NBE", "NBS"]:
ts = initts + datetime.timedelta(hours=int(hr))
ts = initts + timedelta(hours=int(hr))
elif hr == "00":
ts = times[-1] + datetime.timedelta(days=1)
ts = times[-1] + timedelta(days=1)
ts = ts.replace(hour=0)
else:
ts = times[-1].replace(hour=int(hr))
Expand Down
4 changes: 2 additions & 2 deletions src/pyiem/nws/products/pirep.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"""

import datetime
import math
import re
from datetime import timedelta
from typing import List

from metpy.units import units
Expand Down Expand Up @@ -287,7 +287,7 @@ def compute_pirep_valid(self, hour, minute):
hour=hour, minute=minute, second=0, microsecond=0
)
if hour > self.utcnow.hour:
res -= datetime.timedelta(hours=24)
res -= timedelta(hours=24)
return res

def sql(self, txn):
Expand Down
6 changes: 3 additions & 3 deletions src/pyiem/nws/products/saw.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
This does not process the legacy SAW products that did not have LAT...LON
"""

import datetime
import re
from datetime import timedelta
from typing import Optional

from shapely.geometry import MultiPolygon
Expand Down Expand Up @@ -168,10 +168,10 @@ def find_time(self):

# If we are near the end of the month and the day1 is 1, add 1 month
if self.utcnow.day > 27 and day1 == 1:
sts += datetime.timedelta(days=+35)
sts += timedelta(days=+35)
sts = sts.replace(day=1)
if self.utcnow.day > 27 and day2 == 1:
ets += datetime.timedelta(days=+35)
ets += timedelta(days=+35)
ets = ets.replace(day=1)
return (sts, ets)

Expand Down
6 changes: 3 additions & 3 deletions src/pyiem/nws/products/sigmet.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Parse SIGMETs"""

# Stdlib imports
import datetime
import math
import re
from datetime import timedelta

# Third Party
from shapely.geometry import Point, Polygon
Expand Down Expand Up @@ -99,7 +99,7 @@ def figure_expire(ptime, hour, minute):
"""
expire = ptime
if hour < ptime.hour:
expire += datetime.timedelta(days=1)
expire += timedelta(days=1)
return expire.replace(hour=hour, minute=minute)


Expand Down Expand Up @@ -292,7 +292,7 @@ def compute_time(self, ddhhmi):
minute = int(ddhhmi[4:6])
ts = self.valid
if self.valid.day > 25 and day < 5: # next month
ts += datetime.timedelta(days=15)
ts += timedelta(days=15)

return ts.replace(day=day, hour=hour, minute=minute)

Expand Down
6 changes: 3 additions & 3 deletions src/pyiem/nws/products/sps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Special Weather Statement"""

import datetime
import re
from datetime import timedelta

from pyiem import reference
from pyiem.nws.product import TextProduct
Expand Down Expand Up @@ -40,7 +40,7 @@ def dedup_headline(headline, ugcs, counties, expire):
def _sql_segment(prod, txn, seg):
"""Do the database insert for this segment."""
ugcs = [str(s) for s in seg.ugcs]
ets = prod.valid + datetime.timedelta(hours=1)
ets = prod.valid + timedelta(hours=1)
if seg.ugcexpire is not None:
ets = seg.ugcexpire
tml_valid = None
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_jabbers(self, uri, _uri2=None):
counties = f" for {ugcs_to_text(seg.ugcs)}"
expire = ""
if seg.ugcexpire is not None:
_d = seg.ugcexpire - datetime.timedelta(
_d = seg.ugcexpire - timedelta(
hours=reference.offsets.get(self.z, 0)
)
expire = f" till {_d:%-I:%M %p} {self.z}"
Expand Down
8 changes: 4 additions & 4 deletions src/pyiem/nws/ugc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"""

# stdlib
import datetime
import re
from collections import OrderedDict
from datetime import datetime, timedelta
from typing import Optional, Union

# third party
Expand Down Expand Up @@ -59,7 +59,7 @@ def str2time(text, valid):
hour = int(text[2:4])
minute = int(text[4:])
if day < 5 and valid.day > 25: # Next month
valid = valid + datetime.timedelta(days=25)
valid = valid + timedelta(days=25)

return valid.replace(day=day, hour=hour, minute=minute)

Expand Down Expand Up @@ -220,10 +220,10 @@ def __getitem__(self, key):

def parse(
text: str,
valid: datetime.datetime,
valid: datetime,
ugc_provider: Optional[UGCProvider] = None,
is_firewx: bool = False,
) -> tuple[list[UGC], Optional[datetime.datetime]]:
) -> tuple[list[UGC], Optional[datetime]]:
"""Return UGC list and expiration time.
Arguments:
Expand Down

0 comments on commit 6e89d9f

Please sign in to comment.