Compare commits
No commits in common. "master" and "master" have entirely different histories.
11
README.md
11
README.md
|
@ -16,7 +16,7 @@ Installation
|
||||||
|
|
||||||
Clone the repo:
|
Clone the repo:
|
||||||
|
|
||||||
git clone https://git.bitmessage.org/Bitmessage/PyBitMessage_AutoResponder && cd PyBitMessage_AutoResponder
|
git clone https://git.bitmessage.org/prachiyadav/PyBitMessage_AutoResponder && cd PyBitMessage_AutoResponder
|
||||||
|
|
||||||
And.. you're done.
|
And.. you're done.
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Before running this script please run the bitmessages application, because if yo
|
||||||
|
|
||||||
Configuration Steps
|
Configuration Steps
|
||||||
|
|
||||||
1.Put the autoresponder.conf file into the .config directory which contains the database of bitmessage application.
|
1.Put the credentials.ini file into the .config directory which contains the database of bitmessage application.
|
||||||
|
|
||||||
2.To establish a connection, copy and paste these lines into the bitmessagesettings section of the keys.dat file.Note that the values "username" and "password" below are merely examples, and should be replaced by values that cannot feasibly be guessed:
|
2.To establish a connection, copy and paste these lines into the bitmessagesettings section of the keys.dat file.Note that the values "username" and "password" below are merely examples, and should be replaced by values that cannot feasibly be guessed:
|
||||||
--> apienabled = true
|
--> apienabled = true
|
||||||
|
@ -36,4 +36,9 @@ Configuration Steps
|
||||||
--> apipassword = abc@123
|
--> apipassword = abc@123
|
||||||
|
|
||||||
3.For running the application use
|
3.For running the application use
|
||||||
--> python3 autoresponder_mailing.py
|
--> Python autoresponder_mailing.py
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,59 +1,37 @@
|
||||||
#!/usr/bin/python3
|
|
||||||
"""Bitmessage AutoResponder"""
|
"""Bitmessage AutoResponder"""
|
||||||
import base64
|
|
||||||
import configparser
|
import configparser
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import xmlrpc.client
|
import xmlrpclib
|
||||||
|
|
||||||
|
class BitmessageAutoresponder():
|
||||||
class BitmessageAutoresponder(): # pylint: disable=too-many-locals
|
|
||||||
"""Sending and receiving messages through autoresponder"""
|
"""Sending and receiving messages through autoresponder"""
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
db_var = os.path.join(os.environ["HOME"],
|
db_var = os.path.join(os.environ["HOME"], '.config/PyBitmessage/credentials.ini')
|
||||||
'.config/PyBitmessage/autoresponder.conf')
|
|
||||||
config.read(db_var)
|
config.read(db_var)
|
||||||
apiport = config['sqlite3']['apiport']
|
apiport = config['sqlite3']['apiport']
|
||||||
apiinterface = config['sqlite3']['apiinterface']
|
apiinterface = config['sqlite3']['apiinterface']
|
||||||
apiusername = config['sqlite3']['apiusername']
|
apiusername = config['sqlite3']['apiusername']
|
||||||
apipassword = config['sqlite3']['apipassword']
|
apipassword = config['sqlite3']['apipassword']
|
||||||
api = xmlrpc.client.ServerProxy(
|
api = xmlrpclib.ServerProxy("http://%s:%s@%s:%s/"%(apiusername, apipassword, apiinterface, apiport))
|
||||||
"http://%s:%s@%s:%s/"
|
|
||||||
% (apiusername, apipassword, apiinterface, apiport))
|
|
||||||
expire = 300
|
expire = 300
|
||||||
label = "Autoresponder"
|
myaddress_path = os.path.join(os.environ["HOME"],'.config/PyBitmessage/keys.dat')
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.addresses = {}
|
|
||||||
self.track = {}
|
|
||||||
|
|
||||||
def init_address(self):
|
|
||||||
"""generate random address if there isn't one"""
|
|
||||||
try:
|
|
||||||
addresses = json.loads(self.api.listAddresses())['addresses']
|
|
||||||
if addresses:
|
|
||||||
return
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
self.api.createRandomAddress(base64.b64encode(
|
|
||||||
self.label.encode()).decode('ascii'))
|
|
||||||
|
|
||||||
def loop(self):
|
|
||||||
"""Main loop"""
|
|
||||||
for i in json.loads(self.api.listAddresses())['addresses']:
|
|
||||||
self.addresses[i['address']] = True
|
|
||||||
|
|
||||||
|
def send_autorepond_inbox_message(self):
|
||||||
|
"""Sending Auto Message To The Recipient"""
|
||||||
|
track = {}
|
||||||
|
open_file = open(self.myaddress_path)
|
||||||
|
get_file = open_file.read()
|
||||||
|
split_file = get_file.split("\n")
|
||||||
|
for lines in split_file:
|
||||||
|
if len(lines) == 39:
|
||||||
|
if "[" in lines:
|
||||||
|
set_address=lines.strip("[]")
|
||||||
while True:
|
while True:
|
||||||
self.process_inbox_messages()
|
|
||||||
self.cleanup_tracking()
|
|
||||||
self.delete_outbox_messages()
|
|
||||||
time.sleep(10)
|
|
||||||
|
|
||||||
def process_inbox_messages(self):
|
|
||||||
"""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')
|
||||||
|
@ -61,19 +39,23 @@ class BitmessageAutoresponder(): # pylint: disable=too-many-locals
|
||||||
subject = values.get('subject')
|
subject = values.get('subject')
|
||||||
message = values.get('message')
|
message = values.get('message')
|
||||||
try:
|
try:
|
||||||
if time.time() < self.track[toaddress]:
|
if time.time() < track[toaddress]:
|
||||||
continue
|
continue
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
if toaddress in self.addresses:
|
if set_address == toaddress:
|
||||||
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] = time.time() + self.expire
|
track[toaddress] = currenttime + self.expire
|
||||||
|
list_of_time_track = list(key for (key, value) in track.items() if value < currenttime)
|
||||||
|
for address in list_of_time_track:
|
||||||
|
track.pop(address)
|
||||||
|
self.delete_outbox_message()
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
def delete_outbox_messages(self):
|
def delete_outbox_message(self):
|
||||||
"""Deleting Messages from outbox having status
|
"""Deleting Messages from Outbox Having Status ackreceived or msgsentnoackexpected"""
|
||||||
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:
|
||||||
|
@ -82,16 +64,5 @@ 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().send_autorepond_inbox_message()
|
||||||
BitmessageAutoresponder().loop()
|
|
Loading…
Reference in New Issue
Block a user