-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfake_afos_dump.py
More file actions
124 lines (109 loc) · 3.21 KB
/
fake_afos_dump.py
File metadata and controls
124 lines (109 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Dump some stuff without AFOS PILs"""
# Stdlib
import re
import click
from pyiem.nws.product import TextProduct
from twisted.internet import reactor
# Local
from pywwa import common
from pywwa.database import get_database
from pywwa.ldm import bridge
from pywwa.workflows.afos_dump import write2memcache
CWA = re.compile("^FA(AK|HI|US)2([1-6])$")
MIS = re.compile("^FA(AK|HI|US)20$")
GMET = {
"LWGE86": "GMTIFR",
"LWHE00": "GMTTRB",
"LWIE00": "GMTICE",
}
# https://www.nhc.noaa.gov/archive/recon/readme.txt
NHC = {
"URPA15": "AHOPA1",
"URPN15": "AHOPN1",
"URNT15": "AHONT1",
"URNT10": "REPNT0",
"URNT11": "REPNT1",
"URNT12": "REPNT2",
"URNT13": "REPNT3",
"UZNT13": "REPNT3", # checking with NHC
"URNT14": "REPNTS",
"URPA10": "REPPA0",
"URPA11": "REPPA1",
"URPA12": "REPPA2",
"URPA13": "REPPA3",
"UZPA13": "REPPA3", # checking with NHC
"URPN10": "REPPN0",
"URPN11": "REPPN1",
"URPN12": "REPPN2",
"URPN13": "REPPN3",
"UZPN13": "REPPN3", # checking with NHC
"URPN14": "REPPNS",
"UZGL01": "UZGL01", # email to NHC about this
}
def compute_afos(textprod: TextProduct):
"""Our hackery to assign a fake AFOS pil to a product without AFOS"""
ttaaii: str = textprod.wmo
if ttaaii[:4] == "NOXX":
afos = f"ADM{textprod.source[1:]}"
elif ttaaii == "CDUS27":
afos = f"DSM{textprod.source[1:]}"
elif ttaaii.startswith("UB"):
afos = "PIREP"
elif ttaaii in GMET:
afos = GMET[ttaaii]
elif MIS.match(ttaaii):
afos = f"MIS{textprod.source[1:]}"
elif CWA.match(ttaaii):
afos = f"CWA{textprod.source[1:]}"
elif ttaaii[:4] == "FOUS":
afos = f"FRH{ttaaii[4:]}"
elif ttaaii[:2] == "FO" and ttaaii[2:4] in [
"CA",
"UE",
"UM",
"CN",
"GX",
"UW",
]:
afos = f"FRHT{ttaaii[4:]}"
elif textprod.source in ["KNHC", "KWBC"] and ttaaii in NHC:
afos = NHC[ttaaii]
else:
raise Exception(f"Unknown TTAAII {ttaaii} conversion")
textprod.afos = afos
def really_process_data(txn, data):
"""We are called with a hard coded AFOS PIL"""
tp = TextProduct(
data, utcnow=common.utcnow(), ugc_provider={}, parse_segments=False
)
if tp.afos is None:
compute_afos(tp)
sql = (
"INSERT into products "
"(pil, data, source, wmo, entered, bbb) values(%s,%s,%s,%s,%s,%s)"
)
sqlargs = (
tp.afos,
tp.unixtext,
tp.source,
tp.wmo,
tp.valid.strftime("%Y-%m-%d %H:%M+00"),
tp.bbb,
)
if common.dbwrite_enabled():
txn.execute(sql, sqlargs)
# CWA is handled by cwa_parser.py
if tp.afos[:3] not in ["FRH", "CWA", "DSM"]:
jmsgs = tp.get_jabbers(
common.SETTINGS.get("pywwa_product_url", "pywwa_product_url")
)
for jmsg in jmsgs:
common.send_message(*jmsg)
# We are on a thread, so we need to send this back to the main thread
reactor.callFromThread(write2memcache, tp.get_product_id(), tp.unixtext)
return tp
@click.command(help=__doc__)
@common.init
def main(*args, **kwargs):
"""Go Main Go."""
bridge(really_process_data, dbpool=get_database("afos"))