Added configparser

This commit is contained in:
prachi 2020-05-13 21:19:21 +05:30
parent 466cd2327d
commit 8bd4fe036b
No known key found for this signature in database
GPG Key ID: 2940E6901747AAAF
2 changed files with 25 additions and 30 deletions

View File

@ -1,4 +1,4 @@
# PyBitMessgae_AutoResponder # PyBitMessage_AutoResponder
The aim of this python script is to run an bitmessages application automatically.This script will monitor the reponses from Responder and perform accordingly. The aim of this python script is to run an bitmessages application automatically.This script will monitor the reponses from Responder and perform accordingly.

View File

@ -1,15 +1,20 @@
import xmlrpclib import xmlrpclib
import json import json
import time import time
import datetime import time
from datetime import timedelta from datetime import timedelta
import configparser
seconds=300
class Bitmessage_Autorespond_To_Recipient(): class BitmessageAutoresponder():
api = xmlrpclib.ServerProxy("http://prachi.y@cisinlabs.com:7509963795d@localhost:8442/") config = configparser.ConfigParser()
config.read('/home/cis/PyBitmessage/examples/credentials.ini')
apiusername = config['sqlite3']['apiusername']
def api_sending_and_delete_mnessage_through_auto_responder(self): 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""" """Sending Auto Message To The Recipient"""
track={} track={}
while True: while True:
@ -17,50 +22,40 @@ class Bitmessage_Autorespond_To_Recipient():
inbox_var=inboxMessages.get('inboxMessages') inbox_var=inboxMessages.get('inboxMessages')
for values in inbox_var: for values in inbox_var:
msgid=values.get('msgid') msgid=values.get('msgid')
to_address=values.get('fromAddress') toaddress=values.get('fromAddress')
from_address=values.get('toAddress') fromaddress=values.get('toAddress')
subject=values.get('subject') subject=values.get('subject')
message=values.get('message') message=values.get('message')
try: try:
if datetime.datetime.now() < track[to_address]: if time.time() < track[toaddress]:
continue continue
except KeyError: except KeyError:
pass pass
ackData=self.api.sendMessage(to_address,from_address,subject,message) ackData=self.api.sendMessage(toaddress,fromaddress,subject,message)
print 'The ackData is:', ackData print 'The ackData is:', ackData
print("Message Sent")
self.api.trashMessage(msgid) self.api.trashMessage(msgid)
print("Deleted bitmessage") global seconds
seconds = 300 currenttime = time.time()
currenttime_with_date = datetime.datetime.now() track[toaddress]= currenttime + seconds
track[to_address]= currenttime_with_date + timedelta(seconds=seconds) list_of_time_track = list(key for (key,value) in track.items() if value < currenttime)
print("Store time of sending messages",track[to_address])
list_of_time_track = list(key for (key,value) in track.items() if value < currenttime_with_date)
# import pdb;pdb.set_trace()
for t in list_of_time_track: for t in list_of_time_track:
track.pop(t) track.pop(t)
print("------remove address time--------")
print("-----------********_-_*******-----------")
time.sleep(10) time.sleep(10)
def delete_outbox_message(self):
def check_and_delete_outbox_message_recieved_or_not(self):
"""Deleting Messages from Outbox Having Status ackreceived or msgsentnoackexpected""" """Deleting Messages from Outbox Having Status ackreceived or msgsentnoackexpected"""
SentMessage=json.loads(self.api.getAllSentMessages()) SentMessage=json.loads(self.api.getAllSentMessages())
sent_var=SentMessage.get('sentMessages') sent_var=SentMessage.get('sentMessages')
for values in sent_var: for values in sent_var:
status_ack_rcvd=values.get('status') status_ack_rcvd=values.get('status')
ackData=values.get('ackData') ackData=values.get('ackData')
if status_ack_rcvd=='ackreceived' or status_ack_rcvd=='msgsentnoackexpected': if status_ack_rcvd in ('ackreceived','msgsentnoackexpected'):
self.api.trashSentMessageByAckData(ackData) self.api.trashSentMessageByAckData(ackData)
print("deleted outbox messages")
else: else:
print("--------********----------") print("--------********----------")
if __name__ == '__main__': if __name__ == '__main__':
Bitmessage_Autorespond_To_Recipient().api_sending_and_delete_mnessage_through_auto_responder() BitmessageAutoresponder().send_autorepond_inbox_message()
# Bitmessage_Autorespond_To_Recipient().check_and_delete_outbox_message_recieved_or_not() # Bitmessage_Autorespond_To_Recipient().delete_outbox_message()