From fd74397415a5fc8c370b14209b42114187925086 Mon Sep 17 00:00:00 2001 From: Dan Srebnick Date: Wed, 27 Sep 2017 12:00:00 -0400 Subject: [PATCH] Prepare for 0.7 release --- README | 4 +++ noaacap/etc/noaacap.conf | 1 + noaacap/usr/local/bin/noaacap.py | 40 ++++++++++++++++++++--- noaacap/usr/local/share/noaacap/CHANGELOG | 4 +++ noaacap/usr/local/share/noaacap/README | 4 +++ 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README b/README index bf0bdd7..f66661f 100644 --- a/README +++ b/README @@ -49,6 +49,10 @@ at https://alerts.weather.gov/. Only list one county. The program will then send the alert for all affected zones. You could instead use a zone code if you want to be more specific. +myResend should be set to 0 for no message resends or to an interval of your +choosing. If noaacap beacons every 2 minutes, a value of 30 would provide +hourly resends. + USE It would be good to hear from users of this software. Please email diff --git a/noaacap/etc/noaacap.conf b/noaacap/etc/noaacap.conf index daeb100..f5b71fb 100644 --- a/noaacap/etc/noaacap.conf +++ b/noaacap/etc/noaacap.conf @@ -1,3 +1,4 @@ [noaacap] myTZ = America/New_York myZone = NJZ014 +myResend = 0 diff --git a/noaacap/usr/local/bin/noaacap.py b/noaacap/usr/local/bin/noaacap.py index 84954d5..0138e5a 100755 --- a/noaacap/usr/local/bin/noaacap.py +++ b/noaacap/usr/local/bin/noaacap.py @@ -6,7 +6,7 @@ ## ## See /usr/local/share/noaacap/CHANGELOG for change history ## -version = "0.6" +version = "0.7" import sys import pytz @@ -24,7 +24,7 @@ from systemd.journal import JournalHandler log = logging.getLogger('noaacap') log.addHandler(JournalHandler(SYSLOG_IDENTIFIER='noaacap')) -log.setLevel(logging.INFO) +log.setLevel(logging.DEBUG) log.info("Starting") if len(sys.argv) == 2 and sys.argv[1] == '-v': @@ -66,6 +66,14 @@ except: log.error("Check " + conffile + " for proper myZone value in [noaacap] section") Exiting() +try: + myResend = int(config.get('noaacap', 'myResend')) +except: + log.error("Check " + conffile + " for proper myResend value in [noaacap] section") + log.error("Try 0 (for no resend)") + log.error("or 30 (for 1h if beacon cycle-size 2m)") + Exiting() + url = 'https://alerts.weather.gov/cap/wwaatmget.php?x=' + myZone + '&y=0' r = requests.get(url) @@ -152,7 +160,10 @@ for i in range(0, count): else: if i == 0: alerts = db.DB() - alerts.open(dbfile, None, db.DB_HASH, db.DB_CREATE) + alerts.open(dbfile, "Alerts", db.DB_HASH, db.DB_CREATE) + if myResend > 0: + resend = db.DB() + resend.open(dbfile, "Resend", db.DB_HASH, db.DB_CREATE) pp = db.DB() pp.open(ppmap, None, db.DB_HASH, db.DB_RDONLY) @@ -172,11 +183,28 @@ for i in range(0, count): id = bytes(str(Office + Phenomena + Significance + ETN), 'utf-8') + # Do we have this alert? if alerts.has_key(id): + # Is the updated time unchanged? if alerts[id].decode('utf-8') == updated: log.debug(id.decode('utf-8') + " " + updated + " found") - continue - + # Is resend behavoir desired? + if myResend > 0: + + try: + recount = int(resend[id].decode('utf-8')) - 1 + except: + resend[id] = bytes(str(myResend), 'utf-8') + recount = int(resend[id].decode('utf-8')) - 1 + + if recount > 0: + resend[id] = bytes(str(recount), 'utf-8') + log.debug(id.decode('utf-8') + " resend in " + str(recount) + + " iterations") + continue + else: + continue + alerts[id] = updated effutc = aprstime(entries[i].effective.string[0:-6],myTZ) @@ -239,6 +267,8 @@ for i in range(0, count): line = "{" + t + "00" print(":NWS_" + event + ":" + message + line) + if myResend > 0: + resend[id] = bytes(str(myResend), 'utf-8') break diff --git a/noaacap/usr/local/share/noaacap/CHANGELOG b/noaacap/usr/local/share/noaacap/CHANGELOG index d0464f0..d96563b 100644 --- a/noaacap/usr/local/share/noaacap/CHANGELOG +++ b/noaacap/usr/local/share/noaacap/CHANGELOG @@ -1,5 +1,9 @@ noaacap changelog ## +Version: 0.7 +Release: TBD +Added myResend parameter to control message resends. +## Version: 0.6 Release: September 15, 2017 Converted to Python3 diff --git a/noaacap/usr/local/share/noaacap/README b/noaacap/usr/local/share/noaacap/README index 9006014..e6e0afd 100644 --- a/noaacap/usr/local/share/noaacap/README +++ b/noaacap/usr/local/share/noaacap/README @@ -44,6 +44,10 @@ at https://alerts.weather.gov/. Only list one county. The program will then send the alert for all affected zones. You could instead use a zone code if you want to be more specific. +myResend should be set to 0 for no message resends or to an interval of your +choosing. If noaacap beacons every 2 minutes, a value of 30 would provide +hourly resends. + USE It would be good to hear from users of this software. Please email