PyBitMessage_AutoResponder/autoresponder_mailing.py

66 lines
2.4 KiB
Python
Raw Normal View History

import xmlrpclib
import json
import time
2020-05-15 16:14:39 +00:00
import configparser
import os
2020-05-13 15:49:21 +00:00
class BitmessageAutoresponder():
2020-05-15 16:14:39 +00:00
config=configparser.ConfigParser()
db_var=os.path.join(os.environ["HOME"],'.config/PyBitmessage/credentials.ini')
config.read(db_var)
apiport=config['sqlite3']['apiport']
apiinterface=config['sqlite3']['apiinterface']
apiusername=config['sqlite3']['apiusername']
apipassword=config['sqlite3']['apipassword']
api=xmlrpclib.ServerProxy("http://%s:%s@%s:%s/" % (apiusername,apipassword,apiinterface,apiport))
expire=300
2020-05-13 15:49:21 +00:00
def send_autorepond_inbox_message(self):
"""Sending Auto Message To The Recipient"""
2020-05-15 16:14:39 +00:00
cls = self.__class__
track={}
while True:
inboxMessages=json.loads(self.api.getAllInboxMessages())
inbox_var=inboxMessages.get('inboxMessages')
2020-05-15 16:14:39 +00:00
currenttime=time.time()
for values in inbox_var:
msgid=values.get('msgid')
2020-05-13 15:49:21 +00:00
toaddress=values.get('fromAddress')
fromaddress=values.get('toAddress')
subject=values.get('subject')
message=values.get('message')
try:
2020-05-13 15:49:21 +00:00
if time.time() < track[toaddress]:
continue
except KeyError:
2020-05-15 16:14:39 +00:00
pass
if toaddress==fromaddress:
continue
2020-05-13 15:49:21 +00:00
ackData=self.api.sendMessage(toaddress,fromaddress,subject,message)
self.api.trashMessage(msgid)
2020-05-15 16:14:39 +00:00
track[toaddress]=currenttime + cls.expire
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)
2020-05-15 16:14:39 +00:00
self.delete_outbox_message()
time.sleep(10)
2020-05-13 15:49:21 +00:00
def delete_outbox_message(self):
2020-05-15 16:14:39 +00:00
print("hello sent dlt")
"""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 15:49:21 +00:00
if status_ack_rcvd in ('ackreceived','msgsentnoackexpected'):
self.api.trashSentMessageByAckData(ackData)
2020-05-15 16:14:39 +00:00
2020-05-13 15:49:21 +00:00
if __name__ == '__main__':
2020-05-13 15:49:21 +00:00
BitmessageAutoresponder().send_autorepond_inbox_message()