Skip to content

Commit

Permalink
Merge pull request #1077 from akrherz/250121-2
Browse files Browse the repository at this point in the history
✨ Add Aviation AFD, Recent METARS
  • Loading branch information
akrherz authored Jan 22, 2025
2 parents e2fa467 + b6d2330 commit 74fa62d
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 19 deletions.
29 changes: 29 additions & 0 deletions htdocs/sites/taf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$(document).ready(() =>{
const rawtext = $("#rawtext");
const station3 = rawtext.data("station3");
$.ajax({
url: `/cgi-bin/afos/retrieve.py?pil=TAF${station3}&fmt=html`,
success: (data) => {
rawtext.html(data);
}
});

const afd = $("#afd");
const wfo = afd.data("wfo");
$.ajax({
url: `/cgi-bin/afos/retrieve.py?pil=AFD${wfo}&fmt=html&aviation_afd=1`,
success: (data) => {
afd.html(data);
}
});

const metars = $("#metars");
const station4 = metars.data("station4");
$.ajax({
url: `/cgi-bin/request/asos.py?station=${station4}&hours=4&nometa=1&data=metar&report_type=3,4`,
success: (data) => {
metars.html(`<pre>${data}</pre>`);
}
});

});
33 changes: 17 additions & 16 deletions htdocs/sites/taf.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,40 @@
$station3 = substr($station4, 1, 3);

$t = new MyView();
$t->refresh = 300;
$t->title = "Terminal Aerodome Forecasts";
$t->sites_current = "taf";
$t->jsextra = <<<EOM
<script>
$(document).ready(function(){
$.ajax({
url: "/cgi-bin/afos/retrieve.py?pil=TAF{$station3}&fmt=html",
success: function(data){
$("#rawtext").html(data);
}
});
});
</script>
<script src="taf.js" type="text/javascript"></script>
EOM;

$t->content = <<<EOF
$t->content = <<<EOM
<h3>Terminal Aerodome Forecasts</h3>
<p>The IEM processes the feed of Terminal Aerodome Forecasts from the NWS. This
page presents some of the options available for this dataset. A
<a href="/request/taf.php">download option</a> exists as well.</p>
<h4>Raw Text</h4>
<h4>Recent METARs</h4>
<div id="rawtext"></div>
<div id="metars" data-station4="{$station4}"></div>
<h4>IEM Visualization</h4>
<h4>Raw TAF Text</h4>
<div id="rawtext" data-station3="{$station3}"></div>
<h4>Current NWS Aviation AFD</h4>
<div id="afd" data-wfo="{$metadata['wfo']}"></div>
<h4>IEM TAF Visualization</h4>
<p>IEM <a href="/plotting/auto/?q=219&station={$station4}">Autoplot 219</a> produced
this visualization:</p>
<p><img src="/plotting/auto/plot/219/station:{$station4}.png" class="img img-responsive"></p>
EOF;
EOM;
$t->render('sites.phtml');
30 changes: 27 additions & 3 deletions pylib/iemweb/afos/retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
Changelog
~~~~~~~~~
- 2025-01-22: Added `aviation_afd` flag for the specific case of retrieving
the "Aviation" section of an Area Forecast Discussion.
- 2025-01-08: Added some caching due to incessant requests for the same data.
- 2024-08-25: Add ``order`` parameter to allow for order of the returned
products.
Expand Down Expand Up @@ -58,6 +60,7 @@
"""

import re
import zipfile
from datetime import datetime, timedelta, timezone
from io import BytesIO, StringIO
Expand All @@ -70,11 +73,20 @@
from sqlalchemy import text

WARPIL = "FLS FFS AWW TOR SVR FFW SVS LSR SPS WSW FFA WCN NPW".split()
AVIATION_AFD = re.compile(r"^\.AVIATION[\s\.]", re.IGNORECASE | re.MULTILINE)


class MyModel(CGIModel):
"""See how we are called."""

aviation_afd: bool = Field(
False,
description=(
"If set to 1, the returned data will be the 'Aviation' section "
"of an Area Forecast Discussion. This requires the PIL to be "
"an AFD product and a limit of 1 set."
),
)
center: str = Field(
"",
description=(
Expand Down Expand Up @@ -324,19 +336,31 @@ def application(environ, start_response):
sio.write("<br /><pre>\n")
else:
sio.write("\001\n")
payload = row[0]
if (
len(pils) == 1
and pils[0].startswith("AFD")
and environ["aviation_afd"]
):
# Special case for AFD products, we only want the Aviation
# section
parts = payload.split("&&")
for part in parts:
if AVIATION_AFD.search(part):
payload = part
break
# Remove control characters from the product as we are including
# them manually here...
if fmt == "html":
sio.write(
html_escape(row[0])
html_escape(payload)
.replace("\003", "")
.replace("\001\r\r\n", "")
.replace("\r\r\n", "\n")
)
else:
sio.write(
(row[0])
.replace("\003", "")
payload.replace("\003", "")
.replace("\001\r\r\n", "")
.replace("\r\r\n", "\n")
)
Expand Down

0 comments on commit 74fa62d

Please sign in to comment.