From 38d066b26ea29f3cc43dd03f1a369ff89073a0b4 Mon Sep 17 00:00:00 2001 From: Dan Srebnick Date: Tue, 20 Feb 2018 14:18:36 -0500 Subject: [PATCH] Add timeout for slow/no response from NWS servers --- noaacap/DEBIAN/control | 2 +- noaacap/usr/local/bin/noaacap.py | 16 +++++++++++--- noaacap/usr/local/bin/noaacap.py.rej | 27 +++++++++++++++++++++++ noaacap/usr/local/share/noaacap/CHANGELOG | 4 ++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 noaacap/usr/local/bin/noaacap.py.rej diff --git a/noaacap/DEBIAN/control b/noaacap/DEBIAN/control index 0abe274..62350ca 100644 --- a/noaacap/DEBIAN/control +++ b/noaacap/DEBIAN/control @@ -1,5 +1,5 @@ Package: noaacap -Version: 0.8 +Version: 0.9 Section: hamradio Priority: extra Maintainer: Dan Srebnick diff --git a/noaacap/usr/local/bin/noaacap.py b/noaacap/usr/local/bin/noaacap.py index ac2b8fd..200fbdb 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.8" +version = "0.9" import sys import pytz @@ -87,7 +87,12 @@ except: url = 'https://alerts.weather.gov/cap/wwaatmget.php?x=' + myZone + '&y=0' -r = requests.get(url) +try: + r = requests.get(url, timeout=2) +except requests.exceptions.Timeout: + log.error("Timeout exception requesting " + url) + ErrExit() + if r.status_code != 200: log.error(str(r.status_code) + " " + url) ErrExit() @@ -252,7 +257,12 @@ for i in range(0, count): t = t + chr(s+61) # Pull specific alert to get compressed UGC zones - rs = requests.get(entries[i].id.string) + try: + rs = requests.get(entries[i].id.string, timeout=2) + except requests.exceptions.Timeout: + log.error("Timeout exception requesting " + url) + ErrExit() + if rs.status_code != 200: log.error(str(rs.status_code) + " " + rs) ErrExit() diff --git a/noaacap/usr/local/bin/noaacap.py.rej b/noaacap/usr/local/bin/noaacap.py.rej new file mode 100644 index 0000000..249f753 --- /dev/null +++ b/noaacap/usr/local/bin/noaacap.py.rej @@ -0,0 +1,27 @@ +*** /dev/null +--- /dev/null +*************** +*** 9 +- version = "0.9" +--- 9 ----- ++ version = "0.8" +*************** +*** 90,95 +- try: +- r = requests.get(url, timeout=2) +- except requests.exceptions.Timeout: +- log.error("Timeout exception requesting " + url) +- ErrExit() +- +--- 90 ----- ++ r = requests.get(url) +*************** +*** 260,265 +- try: +- rs = requests.get(entries[i].id.string, timeout=2) +- except requests.exceptions.Timeout: +- log.error("Timeout exception requesting " + url) +- ErrExit() +- +--- 255 ----- ++ rs = requests.get(entries[i].id.string) diff --git a/noaacap/usr/local/share/noaacap/CHANGELOG b/noaacap/usr/local/share/noaacap/CHANGELOG index 51c851e..7bc7060 100644 --- a/noaacap/usr/local/share/noaacap/CHANGELOG +++ b/noaacap/usr/local/share/noaacap/CHANGELOG @@ -1,5 +1,9 @@ noaacap changelog ## +Version: 0.9 +Release: February 20, 2018 +Added timeout for non/slow response of NWS servers +## Version: 0.8 Release: January 29, 2018 Added added handling for expired alerts