PyBitMessage_AutoResponder/autoresponder_mailing.py

62 lines
2.4 KiB
Python
Raw Normal View History

import xmlrpclib
import json
import time
2020-05-13 17:49:21 +02:00
import time
from datetime import timedelta
2020-05-13 17:49:21 +02:00
import configparser
seconds=300
2020-05-13 17:49:21 +02:00
class BitmessageAutoresponder():
2020-05-13 17:49:21 +02:00
config = configparser.ConfigParser()
config.read('/home/cis/PyBitmessage/examples/credentials.ini')
apiusername = config['sqlite3']['apiusername']
apipassword = config['sqlite3']['apipassword']
api = xmlrpclib.ServerProxy("http://%s:%s@localhost:8442/" % (apiusername, apipassword))
def send_autorepond_inbox_message(self):
"""Sending Auto Message To The Recipient"""
track={}
while True:
inboxMessages=json.loads(self.api.getAllInboxMessages())
inbox_var=inboxMessages.get('inboxMessages')
for values in inbox_var:
msgid=values.get('msgid')
2020-05-13 17:49:21 +02:00
toaddress=values.get('fromAddress')
fromaddress=values.get('toAddress')
subject=values.get('subject')
message=values.get('message')
try:
2020-05-13 17:49:21 +02:00
if time.time() < track[toaddress]:
continue
except KeyError:
pass
2020-05-13 17:49:21 +02:00
ackData=self.api.sendMessage(toaddress,fromaddress,subject,message)
print 'The ackData is:', ackData
self.api.trashMessage(msgid)
2020-05-13 17:49:21 +02:00
global seconds
currenttime = time.time()
track[toaddress]= currenttime + seconds
list_of_time_track = list(key for (key,value) in track.items() if value < currenttime)
for t in list_of_time_track:
track.pop(t)
time.sleep(10)
2020-05-13 17:49:21 +02:00
def delete_outbox_message(self):
"""Deleting Messages from Outbox Having Status ackreceived or msgsentnoackexpected"""
SentMessage=json.loads(self.api.getAllSentMessages())
sent_var=SentMessage.get('sentMessages')
for values in sent_var:
status_ack_rcvd=values.get('status')
ackData=values.get('ackData')
2020-05-13 17:49:21 +02:00
if status_ack_rcvd in ('ackreceived','msgsentnoackexpected'):
self.api.trashSentMessageByAckData(ackData)
else:
print("--------********----------")
2020-05-13 17:49:21 +02:00
if __name__ == '__main__':
2020-05-13 17:49:21 +02:00
BitmessageAutoresponder().send_autorepond_inbox_message()
# Bitmessage_Autorespond_To_Recipient().delete_outbox_message()