From d6e372140400547c670ae9a144889777038b1beb Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Thu, 21 May 2020 11:13:50 +0800 Subject: [PATCH] Tracking cleanup changes - separate method - loop position --- autoresponder_mailing.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/autoresponder_mailing.py b/autoresponder_mailing.py index f48725b..7af55c4 100644 --- a/autoresponder_mailing.py +++ b/autoresponder_mailing.py @@ -45,6 +45,7 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals while True: self.process_inbox_messages() + self.cleanup_tracking() self.delete_outbox_messages() time.sleep(10) @@ -52,7 +53,6 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals """Loop inbox and process messages""" inboxmessages = json.loads(self.api.getAllInboxMessages()) inbox_var = inboxmessages.get('inboxMessages') - currenttime = time.time() for values in inbox_var: msgid = values.get('msgid') toaddress = values.get('fromAddress') @@ -68,12 +68,7 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals continue self.api.sendMessage(toaddress, fromaddress, subject, message) self.api.trashMessage(msgid) - self.track[toaddress] = currenttime + self.expire - list_of_time_track = list( - key for (key, value) - in self.track.items() if value < currenttime) - for address in list_of_time_track: - self.track.pop(address) + self.track[toaddress] = time.time() + self.expire def delete_outbox_messages(self): """Deleting Messages from outbox having status @@ -86,6 +81,15 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals if status_ack_rcvd in ('ackreceived', 'msgsentnoackexpected'): self.api.trashSentMessageByAckData(ackdata) + def cleanup_tracking(self): + """Expire old tracking data""" + currenttime = time.time() + list_of_time_track = list( + key for (key, value) + in self.track.items() if value < currenttime) + for address in list_of_time_track: + self.track.pop(address) + if __name__ == '__main__': BitmessageAutoresponder().init_address()