Skip to content

Commit

Permalink
update version fetch mech.
Browse files Browse the repository at this point in the history
- use diff source for versions
- now get versions every 12 hours
- bump script ver for release
  • Loading branch information
ironsheep committed Feb 11, 2023
1 parent 4cca023 commit f35c698
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

Sat, 11 Feb 2023 14:28:59 -0700 v1.7.2

- Repair fetch of versions, now every 12 hours

Fri, 10 Feb 2023 17:27:06 -0700 v1.7.1

- Fix internal release number
Expand Down
33 changes: 26 additions & 7 deletions ISP-RPi-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
import sdnotify
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
import urllib3
import requests
from urllib3.exceptions import InsecureRequestWarning

script_version = "1.7.1"
script_version = "1.7.2"
script_name = 'ISP-RPi-mqtt-daemon.py'
script_info = '{} v{}'.format(script_name, script_version)
project_name = 'RPi Reporter MQTT2HA Daemon'
Expand All @@ -35,6 +36,10 @@
# we'll use this throughout
local_tz = get_localzone()

# turn off insecure connection warnings (our KZ0Q site has bad certs)
# REF: https://www.geeksforgeeks.org/how-to-disable-security-certificate-checks-for-requests-in-python/
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)

# TODO:
# - add announcement of free-space and temperatore endpoints

Expand Down Expand Up @@ -222,18 +227,22 @@ def on_publish(client, userdata, mid):
# -----------------------------------------------------------------------------

daemon_version_list = [ 'NOT-LOADED' ]
daemon_last_fetch_time = 0.0

def getDaemonReleases():
# retrieve latest formal release versions list from repo
global daemon_version_list
global daemon_last_fetch_time

newVersionList = []
latestVersion = ''
http = urllib3.PoolManager()
result = http.request('GET', 'https://raw.githubusercontent.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/master/Release')
if result.status != 200:
print_line('- getDaemonReleases() RQST status=({})'.format(result.status), error=True)

response = requests.request('GET', 'http://kz0q.com/daemon-releases', verify=False)
if response.status_code != 200:
print_line('- getDaemonReleases() RQST status=({})'.format(response.status_code), error=True)
daemon_version_list = [ 'NOT-LOADED' ] # mark as NOT fetched
else:
content = result.data.decode('utf-8')
content = response.text
lines = content.split('\n')
for line in lines:
if len(line) > 0:
Expand All @@ -257,8 +266,10 @@ def getDaemonReleases():

daemon_version_list = newVersionList
print_line('- RQST daemon_version_list=({})'.format(daemon_version_list), debug=True)
daemon_last_fetch_time = time() # record when we last fetched the versions

getDaemonReleases() # and load them!
print_line('* daemon_last_fetch_time=({})'.format(daemon_last_fetch_time), debug=True)



Expand Down Expand Up @@ -1561,12 +1572,20 @@ def afterMQTTConnect():

afterMQTTConnect() # now instead of after?

# check every 12 hours (twice a day) = 12 hours * 60 minutes * 60 seconds
kVersionCheckIntervalInSeconds = (12 * 60 * 60)

# now just hang in forever loop until script is stopped externally
try:
while True:
# our INTERVAL timer does the work
sleep(10000)

timeNow = time()
if timeNow > daemon_last_fetch_time + kVersionCheckIntervalInSeconds:
getDaemonReleases() # and load them!


finally:
# cleanup used pins... just because we like cleaning up after us
stopPeriodTimer() # don't leave our timers running!
Expand Down

0 comments on commit f35c698

Please sign in to comment.