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.

View File

@ -1,15 +1,20 @@
import xmlrpclib
import json
import time
import datetime
import time
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']
apipassword = config['sqlite3']['apipassword']
api = xmlrpclib.ServerProxy("http://%s:%s@localhost:8442/" % (apiusername, apipassword))
def api_sending_and_delete_mnessage_through_auto_responder(self):
def send_autorepond_inbox_message(self):
"""Sending Auto Message To The Recipient"""
track={}
while True:
@ -17,50 +22,40 @@ class Bitmessage_Autorespond_To_Recipient():
inbox_var=inboxMessages.get('inboxMessages')
for values in inbox_var:
msgid=values.get('msgid')
to_address=values.get('fromAddress')
from_address=values.get('toAddress')
toaddress=values.get('fromAddress')
fromaddress=values.get('toAddress')
subject=values.get('subject')
message=values.get('message')
try:
if datetime.datetime.now() < track[to_address]:
if time.time() < track[toaddress]:
continue
except KeyError:
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("Message Sent")
self.api.trashMessage(msgid)
print("Deleted bitmessage")
seconds = 300
currenttime_with_date = datetime.datetime.now()
track[to_address]= currenttime_with_date + timedelta(seconds=seconds)
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()
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)
print("------remove address time--------")
print("-----------********_-_*******-----------")
time.sleep(10)
def check_and_delete_outbox_message_recieved_or_not(self):
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')
if status_ack_rcvd=='ackreceived' or status_ack_rcvd=='msgsentnoackexpected':
if status_ack_rcvd in ('ackreceived','msgsentnoackexpected'):
self.api.trashSentMessageByAckData(ackData)
print("deleted outbox messages")
else:
print("--------********----------")
if __name__ == '__main__':
Bitmessage_Autorespond_To_Recipient().api_sending_and_delete_mnessage_through_auto_responder()
# Bitmessage_Autorespond_To_Recipient().check_and_delete_outbox_message_recieved_or_not()
BitmessageAutoresponder().send_autorepond_inbox_message()
# Bitmessage_Autorespond_To_Recipient().delete_outbox_message()