Advertisement
jwinterm

BTCtalksender

May 31st, 2014
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.21 KB | None | 0 0
  1. import csv
  2. import time
  3. import json
  4. from bitcoinrpc.authproxy import AuthServiceProxy
  5.  
  6. #Address to connect with local wallet running as rpc server
  7. url = "http://user:pass@localhost:50554/"
  8.  
  9. #Setup connection and check balance
  10. conn = AuthServiceProxy(url)
  11. data = conn.getbalance()
  12. print data
  13.  
  14. #Open output file for recording transaction ids
  15. outputtx = open('outputtxRound3.txt', 'w')
  16. outputtx.write('{0}, {1}, {2}, {3}\n'.format("list#", "userid", "useraddress", "tx id"))
  17.  
  18. #Run through list of all addresses and only add ones not banned
  19. goodlist = []    #the list of good addresses
  20. with open('TALK.csv', 'rb') as alladdresses:
  21.     reader = csv.reader(alladdresses)
  22.     for row in reader:
  23.         #All bad address have a note in column 5, so if its length is short it's good
  24.         if len(row[5]) < 2:
  25.             goodlist.append(row)
  26.         else:
  27.             print "Banned!!!", row
  28.            
  29. #Run through the goodlist and send coins to each address, make note of tx, and wait
  30. for idx, val in enumerate(goodlist):
  31.     #Make val idx variables explicit
  32.     userid = val[0]
  33.     useraddress = val[1]
  34.     #Check is address is valid
  35.     print "Validating user {0} @ {1}".format(userid, useraddress)
  36.     isvalid = conn.validateaddress(useraddress)[u'isvalid']
  37.     if isvalid == True:
  38.     #Use the following line instead of the preceding one if the script crashes and you need to restart
  39.     #if isvalid == True and idx+1 > 824:
  40.         time.sleep(3)
  41.         #Send coins
  42.         try:
  43.             print "Sending coins to {0} @ {1}".format(userid, useraddress)
  44.             senttx = conn.sendtoaddress(useraddress, 4.20, 'test airdrop 3', 'test airdrop 3')
  45.             print "coins sent!"
  46.             time.sleep(18)
  47.         except:
  48.             print "Failed!"
  49.             senttx = 'FAILED TX - RPC interface error'
  50.             time.sleep(18)    
  51.     elif isvalid != True and idx+1 > 824:
  52.         print "Bad address!!!"
  53.         senttx = 'FAILED TX - invalid address'
  54.     else:
  55.         senttx = 'pass'
  56.  
  57.     #Log user info and tx id
  58.     outputtx.write('{0}, {1}, {2}, {3}\n'.format(idx+1, userid, useraddress, senttx))
  59.  
  60. #Close output file
  61. outputtx.close()
  62.  
  63. #Check balance again
  64. data = conn.getbalance()
  65. print data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement