Tracking cleanup changes

- separate method
- loop position
This commit is contained in:
Peter Šurda 2020-05-21 11:13:50 +08:00
parent a059dcff30
commit d6e3721404
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -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()