Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnibus #1152

Merged
merged 5 commits into from
Mar 7, 2025
Merged

Omnibus #1152

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions htdocs/COOP/extremes.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
$eyear,
);
$jdata = file_get_contents($inturl);
$URI = str_replace($INTERNAL_BASEURL, $EXTERNAL_BASEURL, $inturl);
$URL = str_replace($INTERNAL_BASEURL, $EXTERNAL_BASEURL, $inturl);
$json = json_decode($jdata, $assoc = TRUE);
$data = array();
$table = "";
Expand Down Expand Up @@ -200,7 +200,7 @@

<p>The data found in this table was derived from the following
<a href="/json/">JSON webservice</a>:<br />
<code>{$URI}</code>
<code>{$URL}</code>
</p>

<form method="GET" action="extremes.php" name="myform">
Expand Down
18 changes: 17 additions & 1 deletion htdocs/projects/iembot/channels.html
Original file line number Diff line number Diff line change
Expand Up @@ -1384,6 +1384,22 @@ <h3>NWS Local Office / National Products</h3>
</td>
</tr>
<tr><td>
<a id="channel_SAB" class="btn btn-small" role="button"
href="javascript: revdiv('SAB');"><i class="fa fa-plus"></i></a>
</td><td>Special Avalanche Bulletin (SAB)</td><td><a href="https://weather.gov/directives/sym/pd01017001curr.pdf">10-1701</a></td><td><span class="badge">&lt;afos_pil&gt;</span> <span class="badge">&lt;afos_pil_prefix&gt;...</span></td></tr>
<tr><td colspan="4"><div id="SAB" style="display:none;">
<dl class="dl-horizontal">

<dt>Example Raw Text:</dt>
<dd><a href="https://mesonet.agron.iastate.edu/p.php?pid=202502211335-KPIH-WWUS85-SABPIH">View Text</a></dd>
<dt>Channels for Product Example:</dt><dd><span class="badge">SAB...</span> <span class="badge">SABPIH</span></dd>
<dt>XMPP Chatroom Example:</dt><dd><p>PIH issues <a href="https://mesonet.agron.iastate.edu/p.php?pid=202502211335-KPIH-WWUS85-SABPIH">Special Avalanche Bulletin (SAB)</a> at Feb 21, 6:35 AM MST</p></dd>
<dt>Twitter Example:</dt><dd>#PIH issues Special Avalanche Bulletin (SAB) at Feb 21, 6:35 AM MST https://mesonet.agron.iastate.edu/p.php?pid=202502211335-KPIH-WWUS85-SABPIH<br /></dd>
</dl>
</div>
</td>
</tr>
<tr><td>
<a id="channel_STF" class="btn btn-small" role="button"
href="javascript: revdiv('STF');"><i class="fa fa-plus"></i></a>
</td><td>Tabular State Forecast (STF)</td><td><a href="https://weather.gov/directives/sym/pd01017001curr.pdf">10-1701</a></td><td><span class="badge">&lt;afos_pil&gt;</span> <span class="badge">&lt;afos_pil_prefix&gt;...</span></td></tr>
Expand Down Expand Up @@ -1670,4 +1686,4 @@ <h3>NWS Local Office / National Products</h3>
}
}
</script>


13 changes: 7 additions & 6 deletions htdocs/request/coop/dl.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
$year2 = isset($_GET["year2"]) ? $_GET["year2"] : die("No year2 specified");
$vars = isset($_GET["vars"]) ? $_GET["vars"] : die("No vars specified");

$gis = isset($_GET["gis"]) ? $_GET["gis"] : 'no';
$delim = isset($_GET["delim"]) ? $_GET["delim"] : ",";
$sample = isset($_GET["sample"]) ? $_GET["sample"] : "1min";
$what = isset($_GET["what"]) ? $_GET["what"] : 'dl';
$gis = isset($_GET["gis"]) ? xssafe($_GET["gis"]) : 'no';
$delim = isset($_GET["delim"]) ? xssafe($_GET["delim"]) : ",";
$what = isset($_GET["what"]) ? xssafe($_GET["what"]) : 'dl';

$nt = new NetworkTable($network);
$cities = $nt->table;
Expand All @@ -33,7 +32,7 @@
if ($value == "_ALL") {
$selectAll = true;
}
if (!array_key_exists($value, $cities)) {
if (strlen($value) > 6 && !array_key_exists($value, $cities)) {
xssafe("<tag>");
}
}
Expand Down Expand Up @@ -318,7 +317,9 @@
}
} else if ($what != "plot") {

$rs = pg_exec($connection, $sqlStr);
$stname = uniqid();
pg_prepare($connection, $stname, $sqlStr);
$rs = pg_execute($connection, $stname, Array($stationSQL));

if ($gis == "yes") {
echo "station" . $d[$delim] . "station_name" . $d[$delim] . "lat" . $d[$delim] . "lon" . $d[$delim] . "day" . $d[$delim] . "julianday" . $d[$delim];
Expand Down
33 changes: 3 additions & 30 deletions pylib/iemweb/c/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import os

from pyiem.database import get_sqlalchemy_conn
from sqlalchemy import text
from TileCache.Service import Service

# https://github.com/akrherz/tilecache
from TileCache import InvalidTMSRequest
from TileCache.Service import Service, wsgiHandler
from iemweb.util import tms_handler

tilecachepath, wsgi_file = os.path.split(__file__)
cfgfiles = os.path.join(tilecachepath, "tilecache.cfg")
Expand All @@ -18,28 +15,4 @@ def application(environ, start_response):
"""Go service."""
if not theService["app"]:
theService["app"] = Service.load(cfgfiles)
try:
return wsgiHandler(environ, start_response, theService["app"])
except InvalidTMSRequest:
with get_sqlalchemy_conn("mesosite") as conn:
conn.execute(
text("""
insert into weblog(client_addr, uri, referer, http_status,
x_forwarded_for)
VALUES (:addr, :uri, :ref, :status, :for)
"""),
{
"addr": environ.get(
"HTTP_X_FORWARDED_FOR", environ.get("REMOTE_ADDR")
)
.split(",")[0]
.strip(),
"uri": environ.get("PATH_INFO"),
"ref": environ.get("HTTP_REFERER"),
"status": 404,
"for": environ.get("HTTP_X_FORWARDED_FOR"),
},
)
conn.commit()
start_response("404 Not Found", [("Content-Type", "text/plain")])
return [b"Invalid TMS request"]
return tms_handler(environ, start_response, theService["app"])
38 changes: 3 additions & 35 deletions pylib/iemweb/cache/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

import os

from pyiem.database import get_sqlalchemy_conn
from sqlalchemy import text
from TileCache.Service import Service

# https://github.com/akrherz/tilecache
from TileCache import InvalidTMSRequest
from TileCache.Service import Service, wsgiHandler
from iemweb.util import tms_handler

tilecachepath, wsgi_file = os.path.split(__file__)
cfgfiles = os.path.join(tilecachepath, "tilecache.cfg")
Expand All @@ -18,33 +15,4 @@ def application(environ, start_response):
"""Go service."""
if not theService["app"]:
theService["app"] = Service.load(cfgfiles)
try:
return wsgiHandler(environ, start_response, theService["app"])
except InvalidTMSRequest:
with get_sqlalchemy_conn("mesosite") as conn:
# 5x the 404 logging
conn.execute(
text("""
insert into weblog(client_addr, uri, referer, http_status,
x_forwarded_for)
VALUES (:addr, :uri, :ref, :status, :for),
(:addr, :uri, :ref, :status, :for),
(:addr, :uri, :ref, :status, :for),
(:addr, :uri, :ref, :status, :for),
(:addr, :uri, :ref, :status, :for)
"""),
{
"addr": environ.get(
"HTTP_X_FORWARDED_FOR", environ.get("REMOTE_ADDR")
)
.split(",")[0]
.strip(),
"uri": environ.get("PATH_INFO"),
"ref": environ.get("HTTP_REFERER"),
"status": 404,
"for": environ.get("HTTP_X_FORWARDED_FOR"),
},
)
conn.commit()
start_response("404 Not Found", [("Content-Type", "text/plain")])
return [b"Invalid TMS request"]
return tms_handler(environ, start_response, theService["app"])
34 changes: 34 additions & 0 deletions pylib/iemweb/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@

from datetime import datetime

from pyiem.database import get_sqlalchemy_conn, sql_helper
from TileCache import InvalidTMSRequest
from TileCache.Service import wsgiHandler


def tms_handler(environ: dict, start_response: callable, service: dict):
"""Handler for TMS requests and subsequent failures."""
try:
return wsgiHandler(environ, start_response, service)
except InvalidTMSRequest:
with get_sqlalchemy_conn("mesosite") as conn:
conn.execute(
sql_helper("""
insert into weblog(client_addr, uri, referer, http_status,
x_forwarded_for, domain)
VALUES (:addr, :uri, :ref, :status, :for, :domain)
"""),
{
"addr": environ.get(
"HTTP_X_FORWARDED_FOR", environ.get("REMOTE_ADDR")
)
.split(",")[0]
.strip(),
"uri": environ.get("PATH_INFO"),
"ref": environ.get("HTTP_REFERER"),
"status": 404,
"for": environ.get("HTTP_X_FORWARDED_FOR"),
"domain": environ.get("HTTP_HOST"),
},
)
conn.commit()
start_response("404 Not Found", [("Content-Type", "text/plain")])
return [b"Invalid TMS request"]


def month2months(month: str) -> list[int]:
"""
Expand Down
16 changes: 13 additions & 3 deletions scripts/mrms/mrms_lcref_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pyiem.mrms as mrms
from PIL import Image
from pyiem.reference import ISO8601
from pyiem.util import logger, utc
from pyiem.util import archive_fetch, logger, utc

LOG = logger()

Expand Down Expand Up @@ -179,8 +179,18 @@ def main(valid: datetime):
else:
# If our time is an odd time, run 3 minutes ago
utcnow = utcnow.replace(second=0, microsecond=0)
if utcnow.minute % 2 == 1:
do(utcnow - timedelta(minutes=5), True)
if utcnow.minute % 2 == 0:
LOG.info("Even real-time minute, exiting")
return
valid = utcnow - timedelta(minutes=5)
do(valid, True)
# Also check old dates
for delta in [30, 90, 600, 1440, 2880]:
ts = valid - timedelta(minutes=delta)
ppath = ts.strftime("%Y/%m/%d/GIS/mrms/lcref_%Y%m%d%H%M.png")
with archive_fetch(ppath) as fn:
if fn is None:
do(ts, False)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions tests/urls.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/GIS/apps/rview/warnings.phtml?autopilot=0&osite=AKQ&tzoff=0&lat0=36.98&lon0=-77&layers=nexrad&layers=warnings&layers=watches&layers=blank&layers=cwas&layers=uscounties&site=AKQ&tz=EST&year=2012&month=2&day=29&hour=13&minute=25&warngeo=both&zoom=250&imgsize=800x600&loop=0&frames=10&interval=5&filter=1&cu=1&sortcol=expire&sortdir=0&lsrlook=+/-&lsrwindow=15&extents=-78.333889816361,35.98,-75.666110183639,37.98
/request/awos/1min_dl.php?station%5B%5D=AXA&tz=UTC&year1=2025&month1=1&day1=1&hour1=0&minute1=0&year2=2025&month2=1&day2=1&hour2=0&minute2=0&vars%5B%5D=tmpf&vars%5B%5D=dwpf&sample=1min&what=download&delim=comma&gis=no
/request/coop/dl.php?network=IACLIMATE&station[]=IA8742&year1=2025&month1=03&day1=06&year2=2025&month2=03&day2=07&vars[]=high&vars[]=low&vars[]=precip&what=view&delim=comma&gis=no