Skip to content

Commit

Permalink
Merge pull request #621 from akrherz/231220-2
Browse files Browse the repository at this point in the history
Omnibus
  • Loading branch information
akrherz authored Dec 21, 2023
2 parents 4aaf4d2 + 76392b2 commit 565f956
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
15 changes: 15 additions & 0 deletions cgi-bin/request/asos1min.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ def application(environ, start_response):
if not varnames:
raise IncompleteWebRequest("No vars= was specified in request.")
pgconn, cursor = get_dbconnc("asos1min")
# get a list of columns we have in the alldata_1minute table
cursor.execute(
"select column_name from information_schema.columns where "
"table_name = 'alldata_1minute' ORDER by column_name"
)
columns = []
for row in cursor:
columns.append(row["column_name"])
# cross check varnames now
for varname in varnames:
if varname not in columns:
pgconn.close()
raise IncompleteWebRequest(
f"Unknown variable {varname} specified in request."
)
cursor.execute(
"""
select *,
Expand Down
20 changes: 8 additions & 12 deletions cgi-bin/request/gis/watchwarn.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def build_sql(environ):
utc_updated, hvtec_nwsli, hvtec_severity, hvtec_cause, hvtec_record,
is_emergency, utc_polygon_begin, utc_polygon_end, windtag, hailtag,
tornadotag, damagetag """
if environ.get("accept") == "excel":
cols = cols[4:]

timelimit = f"issue >= '{sts}' and issue < '{ets}'"
if timeopt == 2:
Expand Down Expand Up @@ -192,14 +194,6 @@ def do_excel(sql):
"""Generate an Excel format response."""
with get_sqlalchemy_conn("postgis") as conn:
df = pd.read_sql(sql, conn, index_col=None)
# Drop troublesome columns
df = df.drop(
[
"geo",
],
axis=1,
errors="ignore",
)
# Back-convert datetimes :/
for col in (
"utc_issue utc_expire utc_prodissue utc_updated utc_polygon_begin "
Expand Down Expand Up @@ -229,19 +223,21 @@ def application(environ, start_response):
return [str(exp).encode("ascii")]

accept = environ.get("accept", "shapefile")
pgconn, cursor = get_dbconnc("postgis")
if accept == "excel":
headers = [
("Content-type", EXL),
("Content-disposition", f"attachment; Filename={fn}.xlsx"),
]
start_response("200 OK", headers)
return [do_excel(sql)]
pgconn, cursor = get_dbconnc("postgis")
cursor.close() # lazy
cursor = pgconn.cursor("streaming")

cursor.execute(sql)
if cursor.rowcount == 0:
start_response("200 OK", [("Content-type", "text/plain")])
return [b"ERROR: No results found for query, please try again"]
# TODO if cursor.rowcount == 0:
# start_response("200 OK", [("Content-type", "text/plain")])
# return [b"ERROR: No results found for query, please try again"]

# Filenames are racy, so we need to have a temp folder
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down

0 comments on commit 565f956

Please sign in to comment.