def test_wcn_updates(): """ Make sure our Tags and svs_special works for combined message """ utcnow = utc(2014, 6, 6, 20, 37) ugc_provider = {} for u in range(1, 201, 2): n = 'a' * int(min((u + 1 / 2), 40)) for st in ['AR', 'MS', 'TN', 'MO']: ugc_provider["%sC%03i" % (st, u)] = UGC(st, 'C', "%03i" % (u, ), name=n, wfos=['DMX']) prod = vtecparser(get_test_file('WCNMEG.txt'), utcnow=utcnow, ugc_provider=ugc_provider) j = prod.get_jabbers('http://localhost', 'http://localhost') ans = ( 'MEG updates Severe Thunderstorm Watch (expands area to include ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [MO] and 11 counties in ' '[TN], continues 12 counties in [AR] and ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [MO] and 22 counties in ' '[MS] and aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [TN]) till Jun 6, 7:00 PM ' 'CDT. http://localhost2014-O-EXA-KMEG-SV-A-0240') assert j[0][0] == ans
def test_wcn_updates(): """ Make sure our Tags and svs_special works for combined message """ utcnow = utc(2014, 6, 6, 20, 37) ugc_provider = {} for u in range(1, 201, 2): n = "a" * int(min((u + 1 / 2), 40)) for st in ["AR", "MS", "TN", "MO"]: ugc_provider["%sC%03i" % (st, u)] = UGC(st, "C", "%03i" % (u, ), name=n, wfos=["DMX"]) prod = vtecparser(get_test_file("WCNMEG.txt"), utcnow=utcnow, ugc_provider=ugc_provider) j = prod.get_jabbers("http://localhost", "http://localhost") ans = ( "MEG updates Severe Thunderstorm Watch (expands area to include " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [MO] and 11 counties in " "[TN], continues 12 counties in [AR] and " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [MO] and 22 counties in " "[MS] and aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [TN]) till Jun 6, 7:00 PM " "CDT. http://localhost2014-O-EXA-KMEG-SV-A-0240_2014-06-06T20:37Z") assert j[0][0] == ans
def test_vtec(dbcursor): """Simple test of VTEC parser""" # Remove cruft first dbcursor.execute(""" DELETE from warnings_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' """) dbcursor.execute(""" DELETE from sbw_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' and status = 'NEW' """) ugc_provider = {"MSC091": UGC("MS", "C", "091", "DARYL", ["XXX"])} nwsli_provider = {"AMWI4": NWSLI("AMWI4", "Ames", ["XXX"], -99, 44)} prod = vtecparser( get_test_file("TOR.txt"), ugc_provider=ugc_provider, nwsli_provider=nwsli_provider, ) assert not prod.skip_con assert abs(prod.segments[0].sbw.area - 0.3053) < 0.0001 prod.sql(dbcursor) # See if we got it in the database! dbcursor.execute(""" SELECT issue from warnings_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' and status = 'NEW' """) assert dbcursor.rowcount == 3 dbcursor.execute(""" SELECT issue from sbw_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' and status = 'NEW' """) assert dbcursor.rowcount == 1 msgs = prod.get_jabbers("http://localhost", "http://localhost/") ans = ("JAN issues Tornado Warning for " "((MSC035)), ((MSC073)), DARYL [MS] till Aug 29, 1:15 PM CDT * AT " "1150 AM CDT...THE NATIONAL WEATHER SERVICE HAS ISSUED A " "TORNADO WARNING FOR DESTRUCTIVE WINDS OVER 110 MPH IN THE EYE " "WALL AND INNER RAIN BANDS OF HURRICANE KATRINA. THESE WINDS " "WILL OVERSPREAD MARION...FORREST AND LAMAR COUNTIES DURING " "THE WARNING PERIOD. " "http://localhost2005-O-NEW-KJAN-TO-W-0130_2005-08-29T16:51Z") assert msgs[0][0] == ans
def test_vtec(dbcursor): """Simple test of VTEC parser""" # Remove cruft first dbcursor.execute(""" DELETE from warnings_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' """) dbcursor.execute(""" DELETE from sbw_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' and status = 'NEW' """) ugc_provider = {'MSC091': UGC('MS', 'C', '091', 'DARYL', ['XXX'])} nwsli_provider = {'AMWI4': NWSLI('AMWI4', 'Ames', ['XXX'], -99, 44)} prod = vtecparser(get_test_file('TOR.txt'), ugc_provider=ugc_provider, nwsli_provider=nwsli_provider) assert not prod.skip_con assert abs(prod.segments[0].sbw.area - 0.3053) < 0.0001 prod.sql(dbcursor) # See if we got it in the database! dbcursor.execute(""" SELECT issue from warnings_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' and status = 'NEW' """) assert dbcursor.rowcount == 3 dbcursor.execute(""" SELECT issue from sbw_2005 WHERE wfo = 'JAN' and eventid = 130 and phenomena = 'TO' and significance = 'W' and status = 'NEW' """) assert dbcursor.rowcount == 1 msgs = prod.get_jabbers('http://localhost', 'http://localhost/') ans = ('JAN issues Tornado Warning for ' '((MSC035)), ((MSC073)), DARYL [MS] till Aug 29, 1:15 PM CDT * AT ' '1150 AM CDT...THE NATIONAL WEATHER SERVICE HAS ISSUED A ' 'TORNADO WARNING FOR DESTRUCTIVE WINDS OVER 110 MPH IN THE EYE ' 'WALL AND INNER RAIN BANDS OF HURRICANE KATRINA. THESE WINDS ' 'WILL OVERSPREAD MARION...FORREST AND LAMAR COUNTIES DURING ' 'THE WARNING PERIOD. http://localhost2005-O-NEW-KJAN-TO-W-0130') assert msgs[0][0] == ans
def test_wcn(): """Special tweet logic for cancels and continues NOTE: with updated twitter tweet chars, these tests are not as fun """ utcnow = utc(2014, 6, 3) ugc_provider = {} for u in range(1, 201, 2): n = "a" * int(min((u + 1 / 2), 40)) ugc_provider["IAC%03i" % (u, )] = UGC("IA", "C", "%03i" % (u, ), name=n, wfos=["DMX"]) prod = vtecparser(get_test_file("SVS.txt"), utcnow=utcnow, ugc_provider=ugc_provider) j = prod.get_jabbers("http://localhost/", "http://localhost/") assert prod.is_homogeneous() ans = ("DMX updates Severe Thunderstorm Warning [wind: 60 MPH, hail: " "<.75 IN] (cancels aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " "[IA], continues aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [IA]) " "till 10:45 PM CDT " "http://localhost/2014-O-CON-KDMX-SV-W-0143_2014-06-03T00:00Z") assert j[0][2]["twitter"] == ans prod = vtecparser(get_test_file("WCN.txt"), utcnow=utcnow, ugc_provider=ugc_provider) j = prod.get_jabbers("http://localhost/", "http://localhost/") assert prod.is_homogeneous() ans = ("DMX updates Tornado Watch (cancels a, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [IA], continues 12 counties " "in [IA]) till Jun 4, 1:00 AM CDT " "http://localhost/2014-O-CON-KDMX-TO-A-0210_2014-06-03T00:00Z") assert j[0][2]["twitter"] == ans ans = ("DMX updates Tornado Watch (cancels a, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa [IA], continues 12 counties " "in [IA]) till Jun 4, 1:00 AM CDT. " "http://localhost/2014-O-CON-KDMX-TO-A-0210_2014-06-03T00:00Z") assert j[0][0] == ans
def test_wcn(): """Special tweet logic for cancels and continues NOTE: with updated twitter tweet chars, these tests are not as fun """ utcnow = utc(2014, 6, 3) ugc_provider = {} for u in range(1, 201, 2): n = 'a' * int(min((u + 1 / 2), 40)) ugc_provider["IAC%03i" % (u, )] = UGC('IA', 'C', "%03i" % (u, ), name=n, wfos=['DMX']) prod = vtecparser(get_test_file('SVS.txt'), utcnow=utcnow, ugc_provider=ugc_provider) j = prod.get_jabbers('http://localhost/', 'http://localhost/') assert prod.is_homogeneous() ans = ("DMX updates Severe Thunderstorm Warning [wind: 60 MPH, hail: " "<.75 IN] (cancels aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa " "[IA], continues aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [IA]) " "till 10:45 PM CDT http://localhost/2014-O-CON-KDMX-SV-W-0143") assert j[0][2]['twitter'] == ans prod = vtecparser(get_test_file('WCN.txt'), utcnow=utcnow, ugc_provider=ugc_provider) j = prod.get_jabbers('http://localhost/', 'http://localhost/') assert prod.is_homogeneous() assert j[0][2]['twitter'], ( "DMX updates Tornado Watch (cancels a, " "aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" "aaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaa" "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa [IA], continues 12 counties " "in [IA]) till Jun 4, 1:00 AM CDT " "http://localhost/2014-O-CON-KDMX-TO-A-0210") assert j[0][0], ( 'DMX updates Tornado Watch (cancels a, ' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' 'aaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaa' 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaa [IA], continues 12 counties ' 'in [IA]) till Jun 4, 1:00 AM CDT. ' 'http://localhost/2014-O-CON-KDMX-TO-A-0210')
def load_ugc(txn): """ load ugc dict """ # Careful here not to load things from the future txn.execute( """ SELECT name, ugc, wfo from ugcs WHERE name IS NOT Null and begin_ts < now() and (end_ts is null or end_ts > now()) """ ) for row in txn.fetchall(): nm = (row["name"]).replace("\x92", " ").replace("\xc2", " ") wfos = re.findall(r"([A-Z][A-Z][A-Z])", row["wfo"]) ugc_provider[row["ugc"]] = UGC( row["ugc"][:2], row["ugc"][2], row["ugc"][3:], name=nm, wfos=wfos ) log.msg("ugc_dict is loaded...")
def test_140731_badugclabel(): """ Make sure this says zones and not counties! """ ugc_provider = {} for u in range(530, 550, 1): n = 'a' * min((u + 1 / 2), 80) ugc_provider["ANZ%03i" % (u, )] = UGC('AN', 'Z', "%03i" % (u, ), name=n, wfos=['DMX']) utcnow = utc(2014, 7, 31, 17, 35) prod = vtecparser(get_test_file('MWWLWX.txt'), utcnow=utcnow, ugc_provider=ugc_provider) assert not prod.segments[0].is_emergency j = prod.get_jabbers('http://localhost', 'http://localhost') ans = ('LWX issues Small Craft Advisory ' 'valid at Jul 31, 6:00 PM EDT for 7 forecast zones in [AN] till ' 'Aug 1, 6:00 AM EDT http://localhost2014-O-NEW-KLWX-SC-Y-0151') assert j[0][0] == ans
def test_140731_badugclabel(): """ Make sure this says zones and not counties! """ ugc_provider = {} for u in range(530, 550, 1): n = "a" * min((u + 1 / 2), 80) ugc_provider["ANZ%03i" % (u, )] = UGC("AN", "Z", "%03i" % (u, ), name=n, wfos=["DMX"]) utcnow = utc(2014, 7, 31, 17, 35) prod = vtecparser(get_test_file("MWWLWX.txt"), utcnow=utcnow, ugc_provider=ugc_provider) assert not prod.segments[0].is_emergency j = prod.get_jabbers("http://localhost", "http://localhost") ans = ("LWX issues Small Craft Advisory " "valid at Jul 31, 6:00 PM EDT for 7 forecast zones in [AN] till " "Aug 1, 6:00 AM EDT " "http://localhost2014-O-NEW-KLWX-SC-Y-0151_2014-07-31T22:00Z") assert j[0][0] == ans
def test_sps(dbcursor): """Can we parse a SPS properly, yes we can!""" ugc_provider = {'ALZ039': UGC("AL", "Z", "039", name='Marengo')} prod = spsparser(get_test_file('SPSBMX.txt'), ugc_provider=ugc_provider) jmsgs = prod.get_jabbers('http://localhost') assert len(prod.segments) == 2 assert len(jmsgs) == 1 expected = ("<p>BMX issues <a href='http://localhost?pid=201805292152-" "KBMX-WWUS84-SPSBMX'>SIGNIFICANT WEATHER ADVISORY FOR " "SOUTHWESTERN MARENGO COUNTY UNTIL 515 PM CDT</a></p>") assert jmsgs[0][1] == expected assert 'SPSBMX' in jmsgs[0][2]['channels'] assert 'SPS...' in jmsgs[0][2]['channels'] assert 'SPSBMX.ALZ039' in jmsgs[0][2]['channels'] assert 'ALZ039' in jmsgs[0][2]['channels'] prod.sql(dbcursor) dbcursor.execute( """ SELECT count(*) from text_products where product_id = %s """, (prod.get_product_id(), )) assert dbcursor.fetchall()[0]['count'] == 1
def load_dicts(): """Load up the directionaries""" pgconn = get_dbconn("postgis") cursor = pgconn.cursor(cursor_factory=psycopg2.extras.DictCursor) sql = """ SELECT name, ugc, wfo from ugcs WHERE name IS NOT Null and end_ts is null """ cursor.execute(sql) for row in cursor: nm = (row["name"]).replace("\x92", " ").replace("\xc2", " ") wfos = re.findall(r"([A-Z][A-Z][A-Z])", row["wfo"]) ugc_dict[row["ugc"]] = UGC( row["ugc"][:2], row["ugc"][2], row["ugc"][3:], name=nm, wfos=wfos ) sql = """SELECT nwsli, river_name || ' ' || proximity || ' ' || name || ' ['||state||']' as rname from hvtec_nwsli""" cursor.execute(sql) for row in cursor: nm = row["rname"].replace("&", " and ") nwsli_dict[row["nwsli"]] = NWSLI(row["nwsli"], name=nm)
def test_affected_wfos(): """see what affected WFOs we have """ ugc_provider = {'IAZ006': UGC('IA', 'Z', '006', wfos=['DMX'])} prod = vtecparser(get_test_file('WSWDMX/WSW_00.txt'), ugc_provider=ugc_provider) assert prod.segments[0].get_affected_wfos()[0] == 'DMX'
def test_affected_wfos(): """see what affected WFOs we have """ ugc_provider = {"IAZ006": UGC("IA", "Z", "006", wfos=["DMX"])} prod = vtecparser(get_test_file("WSWDMX/WSW_00.txt"), ugc_provider=ugc_provider) assert prod.segments[0].get_affected_wfos()[0] == "DMX"