Tracking cleanup changes
- separate method - loop position
This commit is contained in:
parent
a059dcff30
commit
d6e3721404
|
@ -45,6 +45,7 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
self.process_inbox_messages()
|
self.process_inbox_messages()
|
||||||
|
self.cleanup_tracking()
|
||||||
self.delete_outbox_messages()
|
self.delete_outbox_messages()
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
|
@ -52,7 +53,6 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals
|
||||||
"""Loop inbox and process messages"""
|
"""Loop inbox and process messages"""
|
||||||
inboxmessages = json.loads(self.api.getAllInboxMessages())
|
inboxmessages = json.loads(self.api.getAllInboxMessages())
|
||||||
inbox_var = inboxmessages.get('inboxMessages')
|
inbox_var = inboxmessages.get('inboxMessages')
|
||||||
currenttime = time.time()
|
|
||||||
for values in inbox_var:
|
for values in inbox_var:
|
||||||
msgid = values.get('msgid')
|
msgid = values.get('msgid')
|
||||||
toaddress = values.get('fromAddress')
|
toaddress = values.get('fromAddress')
|
||||||
|
@ -68,12 +68,7 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals
|
||||||
continue
|
continue
|
||||||
self.api.sendMessage(toaddress, fromaddress, subject, message)
|
self.api.sendMessage(toaddress, fromaddress, subject, message)
|
||||||
self.api.trashMessage(msgid)
|
self.api.trashMessage(msgid)
|
||||||
self.track[toaddress] = currenttime + self.expire
|
self.track[toaddress] = time.time() + 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)
|
|
||||||
|
|
||||||
def delete_outbox_messages(self):
|
def delete_outbox_messages(self):
|
||||||
"""Deleting Messages from outbox having status
|
"""Deleting Messages from outbox having status
|
||||||
|
@ -86,6 +81,15 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals
|
||||||
if status_ack_rcvd in ('ackreceived', 'msgsentnoackexpected'):
|
if status_ack_rcvd in ('ackreceived', 'msgsentnoackexpected'):
|
||||||
self.api.trashSentMessageByAckData(ackdata)
|
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__':
|
if __name__ == '__main__':
|
||||||
BitmessageAutoresponder().init_address()
|
BitmessageAutoresponder().init_address()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user