From 340f8928b353aca6d381a9d60a419aa112100960 Mon Sep 17 00:00:00 2001 From: A_D Date: Thu, 23 Jul 2020 18:38:55 +0200 Subject: [PATCH] switched to using config for last update time --- plugins/inara.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/plugins/inara.py b/plugins/inara.py index 4242dcdf..a8b3ee8d 100644 --- a/plugins/inara.py +++ b/plugins/inara.py @@ -50,7 +50,9 @@ this.loadout = None this.fleet = None this.shipswap = False # just swapped ship -this.last_update_time = time.time() # last time we updated (set to now because we're going to update quickly) +# last time we updated, if unset in config this is 0, which means an instant update +LAST_UPDATE_CONF_KEY = 'inara_last_update' +# this.last_update_time = config.getint(LAST_UPDATE_CONF_KEY) FLOOD_LIMIT_SECONDS = 30 # minimum time between sending events this.timer_run = True @@ -442,10 +444,6 @@ def journal_entry(cmdr, is_beta, system, station, entry, state): cargo = [OrderedDict([('itemName', k), ('itemCount', state['Cargo'][k])]) for k in sorted(state['Cargo'])] - # if our cargo differers from last we checked, we're at a station, - # and our flood limit isnt covered, queue an update - should_poll = this.cargo != cargo and time.time() - this.last_update_time > FLOOD_LIMIT_SECONDS - # Send cargo and materials if changed if this.cargo != cargo: add_event('setCommanderInventoryCargo', entry['timestamp'], cargo) @@ -861,7 +859,7 @@ def add_event(name, timestamp, data): def call_timer(wait=FLOOD_LIMIT_SECONDS): while this.timer_run: time.sleep(wait) - print("INARA: TICK") + print(f"INARA: {time.asctime()} TICK") if this.timer_run: # check again in here just in case we're closing and the stars align call() @@ -870,11 +868,11 @@ def call(callback=None, force=False): if not this.events: return - if (time.time() - this.last_update_time) <= FLOOD_LIMIT_SECONDS and not force: + if (time.time() - config.getint(LAST_UPDATE_CONF_KEY)) <= FLOOD_LIMIT_SECONDS and not force: return - this.last_update_time = time.time() - print(f"INARA: {time.asctime()}sending {len(this.events)} entries to inara (call)") + config.set(LAST_UPDATE_CONF_KEY, int(time.time())) + print(f"INARA: {time.asctime()} sending {len(this.events)} entries to inara (call)") data = OrderedDict([ ('header', OrderedDict([ ('appName', applongname), @@ -897,7 +895,7 @@ def worker(): else: (url, data, callback) = item - print(f"INARA: {time.asctime()}sending {len(data['events'])} entries to inara (worker)") + print(f"INARA: {time.asctime()} sending {len(data['events'])} entries to inara (worker)") retrying = 0 while retrying < 3: