PyBitmessage/src/api client.py

61 lines
2.6 KiB
Python
Raw Normal View History

2013-03-19 18:32:37 +01:00
# This is an example of how to connect to and use the Bitmessage API.
# See https://bitmessage.org/wiki/API_Reference
import xmlrpclib
import json
2013-05-03 23:26:29 +02:00
import time
2013-03-19 18:32:37 +01:00
api = xmlrpclib.ServerProxy("http://bradley:password@localhost:8442/")
print 'Let\'s test the API first.'
inputstr1 = "hello"
inputstr2 = "world"
print api.helloWorld(inputstr1, inputstr2)
print api.add(2,3)
print 'Let\'s set the status bar message.'
2013-03-19 19:39:24 +01:00
print api.statusBar("new status bar message")
2013-03-19 18:32:37 +01:00
print 'Let\'s list our addresses:'
print api.listAddresses()
print 'Let\'s list our address again, but this time let\'s parse the json data into a Python data structure:'
jsonAddresses = json.loads(api.listAddresses())
print jsonAddresses
print 'Now that we have our address data in a nice Python data structure, let\'s look at the first address (index 0) and print its label:'
print jsonAddresses['addresses'][0]['label']
print 'Uncomment the next two lines to create a new random address with slightly a slightly higher difficulty setting than normal.'
#addressLabel = 'new address label'.encode('base64')
#print api.createRandomAddress(addressLabel,False,1.05,1.1111)
2013-03-19 18:32:37 +01:00
print 'Uncomment these next four lines to create new deterministic addresses.'
#passphrase = 'asdfasdfqwser'.encode('base64')
2013-05-02 21:39:51 +02:00
#jsonDeterministicAddresses = api.createDeterministicAddresses(passphrase, 2, 3, 1, False)
2013-03-19 18:32:37 +01:00
#print jsonDeterministicAddresses
#print json.loads(jsonDeterministicAddresses)
print 'Let\'s now print all of our inbox messages:'
print api.getAllInboxMessages()
inboxMessages = json.loads(api.getAllInboxMessages())
print inboxMessages
print 'Uncomment this next line to decode the actual message data in the first message:'
#print inboxMessages['inboxMessages'][0]['message'].decode('base64')
print 'Uncomment this next line in the code to delete a message'
#print api.trashMessage('584e5826947242a82cb883c8b39ac4a14959f14c228c0fbe6399f73e2cba5b59')
2013-05-03 23:26:29 +02:00
print 'Uncomment these lines to send a message. The example addresses are invalid; you will have to put your own in.'
#subject = 'subject!'.encode('base64')
#message = 'Hello, this is the message'.encode('base64')
#ackData = api.sendMessage('BM-Gtsm7PUabZecs3qTeXbNPmqx3xtHCSXF', 'BM-2DCutnUZG16WiW3mdAm66jJUSCUv88xLgS', subject,message)
#print 'The ackData is:', ackData
#while True:
# time.sleep(2)
# print 'Current status:', api.getStatus(ackData)
print 'Uncomment these lines to send a broadcast. The example address is invalid; you will have to put your own in.'
#subject = 'subject within broadcast'.encode('base64')
#message = 'Hello, this is the message within a broadcast.'.encode('base64')
#print api.sendBroadcast('BM-onf6V1RELPgeNN6xw9yhpAiNiRexSRD4e', subject,message)