api_client example standards validation #1491
|
@ -1,72 +1,77 @@
|
||||||
# This is an example of how to connect to and use the Bitmessage API.
|
# This is an example of how to connect to and use the Bitmessage API.
|
||||||
# See https://bitmessage.org/wiki/API_Reference
|
# See https://bitmessage.org/wiki/API_Reference
|
||||||
|
|
||||||
import xmlrpclib
|
|
||||||
import json
|
import json
|
||||||
import time
|
import xmlrpclib
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
api = xmlrpclib.ServerProxy("http://bradley:password@localhost:8442/")
|
api = xmlrpclib.ServerProxy("http://bradley:password@localhost:8442/")
|
||||||
|
|
||||||
print 'Let\'s test the API first.'
|
print('Let\'s test the API first.')
|
||||||
inputstr1 = "hello"
|
inputstr1 = "hello"
|
||||||
inputstr2 = "world"
|
inputstr2 = "world"
|
||||||
print api.helloWorld(inputstr1, inputstr2)
|
print(api.helloWorld(inputstr1, inputstr2))
|
||||||
print api.add(2,3)
|
print(api.add(2, 3))
|
||||||
|
|
||||||
print 'Let\'s set the status bar message.'
|
print('Let\'s set the status bar message.')
|
||||||
print api.statusBar("new status bar message")
|
print(api.statusBar("new status bar message"))
|
||||||
|
|
||||||
print 'Let\'s list our addresses:'
|
print('Let\'s list our addresses:')
|
||||||
print api.listAddresses()
|
print(api.listAddresses())
|
||||||
|
|
||||||
print 'Let\'s list our address again, but this time let\'s parse the json data into a Python data structure:'
|
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())
|
jsonAddresses = json.loads(api.listAddresses())
|
||||||
print jsonAddresses
|
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('Now that we have our address data in a nice Python data structure,'
|
||||||
print jsonAddresses['addresses'][0]['label']
|
' 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 a slightly higher difficulty setting than normal.'
|
print('Uncomment the next two lines to create a new random address'
|
||||||
#addressLabel = 'new address label'.encode('base64')
|
' with a slightly higher difficulty setting than normal.')
|
||||||
#print api.createRandomAddress(addressLabel,False,1.05,1.1111)
|
# addressLabel = 'new address label'.encode('base64')
|
||||||
|
# print api.createRandomAddress(addressLabel,False,1.05,1.1111)
|
||||||
|
|
||||||
print 'Uncomment these next four lines to create new deterministic addresses.'
|
print('Uncomment these next four lines to create new deterministic addresses.')
|
||||||
#passphrase = 'asdfasdfqwser'.encode('base64')
|
# passphrase = 'asdfasdfqwser'.encode('base64')
|
||||||
#jsonDeterministicAddresses = api.createDeterministicAddresses(passphrase, 2, 4, 1, False)
|
# jsonDeterministicAddresses = api.createDeterministicAddresses(passphrase, 2, 4, 1, False)
|
||||||
#print jsonDeterministicAddresses
|
# print jsonDeterministicAddresses
|
||||||
#print json.loads(jsonDeterministicAddresses)
|
# print json.loads(jsonDeterministicAddresses)
|
||||||
|
|
||||||
#print 'Uncomment this next line to print the first deterministic address that would be generated with the given passphrase. This will Not add it to the Bitmessage interface or the keys.dat file.'
|
# print 'Uncomment this next line to print the first deterministic address that would be generated
|
||||||
#print api.getDeterministicAddress('asdfasdfqwser'.encode('base64'),4,1)
|
# with the given passphrase.This will Not add it to the Bitmessage interface or the keys.dat file.'
|
||||||
|
# print api.getDeterministicAddress('asdfasdfqwser'.encode('base64'),4,1)
|
||||||
|
|
||||||
#print 'Uncomment this line to subscribe to an address. (You must use your own address, this one is invalid).'
|
# print 'Uncomment this line to subscribe to an address. (You must use your own address, this one is invalid).'
|
||||||
#print api.addSubscription('2D94G5d8yp237GGqAheoecBYpdehdT3dha','test sub'.encode('base64'))
|
# print api.addSubscription('2D94G5d8yp237GGqAheoecBYpdehdT3dha','test sub'.encode('base64'))
|
||||||
|
|
||||||
#print 'Uncomment this line to unsubscribe from an address.'
|
# print 'Uncomment this line to unsubscribe from an address.'
|
||||||
#print api.deleteSubscription('2D94G5d8yp237GGqAheoecBYpdehdT3dha')
|
# print api.deleteSubscription('2D94G5d8yp237GGqAheoecBYpdehdT3dha')
|
||||||
|
|
||||||
print 'Let\'s now print all of our inbox messages:'
|
print('Let\'s now print all of our inbox messages:')
|
||||||
print api.getAllInboxMessages()
|
print(api.getAllInboxMessages())
|
||||||
inboxMessages = json.loads(api.getAllInboxMessages())
|
inboxMessages = json.loads(api.getAllInboxMessages())
|
||||||
print inboxMessages
|
print(inboxMessages)
|
||||||
|
|
||||||
print 'Uncomment this next line to decode the actual message data in the first message:'
|
print('Uncomment this next line to decode the actual message data in the first message:')
|
||||||
#print inboxMessages['inboxMessages'][0]['message'].decode('base64')
|
# print inboxMessages['inboxMessages'][0]['message'].decode('base64')
|
||||||
|
|
||||||
print 'Uncomment this next line in the code to delete a message'
|
print('Uncomment this next line in the code to delete a message')
|
||||||
#print api.trashMessage('584e5826947242a82cb883c8b39ac4a14959f14c228c0fbe6399f73e2cba5b59')
|
# print api.trashMessage('584e5826947242a82cb883c8b39ac4a14959f14c228c0fbe6399f73e2cba5b59')
|
||||||
|
|
||||||
print 'Uncomment these lines to send a message. The example addresses are invalid; you will have to put your own in.'
|
print('Uncomment these lines to send a message. The example addresses are invalid;'
|
||||||
#subject = 'subject!'.encode('base64')
|
' you will have to put your own in.')
|
||||||
#message = 'Hello, this is the message'.encode('base64')
|
# subject = 'subject!'.encode('base64')
|
||||||
#ackData = api.sendMessage('BM-Gtsm7PUabZecs3qTeXbNPmqx3xtHCSXF', 'BM-2DCutnUZG16WiW3mdAm66jJUSCUv88xLgS', subject,message)
|
# message = 'Hello, this is the message'.encode('base64')
|
||||||
#print 'The ackData is:', ackData
|
# ackData = api.sendMessage('BM-Gtsm7PUabZecs3qTeXbNPmqx3xtHCSXF',
|
||||||
|
|||||||
#while True:
|
# 'BM-2DCutnUZG16WiW3mdAm66jJUSCUv88xLgS', subject,message)
|
||||||
|
# print 'The ackData is:', ackData
|
||||||
|
# while True:
|
||||||
# time.sleep(2)
|
# time.sleep(2)
|
||||||
# print 'Current status:', api.getStatus(ackData)
|
# 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.'
|
print('Uncomment these lines to send a broadcast. The example address is invalid;'
|
||||||
#subject = 'subject within broadcast'.encode('base64')
|
' you will have to put your own in.')
|
||||||
#message = 'Hello, this is the message within a broadcast.'.encode('base64')
|
# subject = 'subject within broadcast'.encode('base64')
|
||||||
#print api.sendBroadcast('BM-onf6V1RELPgeNN6xw9yhpAiNiRexSRD4e', subject,message)
|
# message = 'Hello, this is the message within a broadcast.'.encode('base64')
|
||||||
|
# print api.sendBroadcast('BM-onf6V1RELPgeNN6xw9yhpAiNiRexSRD4e', subject,message)
|
||||||
|
|
Reference in New Issue
Block a user
As for me, this
print
makes no sense: it tells about the comment line which user doesn't see. Maybe for that reason it was commented (^ plenty of them ahead (8just to unclutter the screen at runtime and keep syntax hilite