Advertisement
The_Exile

Bitvisitor.com python script

Jan 2nd, 2013
4,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.32 KB | None | 0 0
  1. '''
  2. This script allows you to use bitvisitor.com without having to open it in a webbrowser.
  3. However, you will still have to wait the 5 minutes and enter the captchas manually.
  4. It is mainly a console application, but a small window will ask you for the captchas.
  5.  
  6. This script was tested with Python 2.7 on Windows 7. Besides the standard stuff,
  7. it depends on BeautifulSoup (http://www.crummy.com/software/BeautifulSoup/)
  8. and PIL (http://www.pythonware.com/products/pil/).
  9.  
  10. usage: pyvisitor.py [-h] [-u path] [-a address]        (all arguments are optional)
  11.  
  12. optional arguments:
  13.  -h, --help                      Show this help message and exit.
  14.  -u path, --user-agents path     A path to a file containing a user-agent on each line.
  15.  -a address, --address address   Your bitcoin address. If omitted, you will be prompted.
  16.  
  17. Created on 02.01.2013
  18. Last update on 30.07.2013
  19. @author: The_Exile (http://www.reddit.com/user/the_exiled_one/)
  20. Feel free to drop me a coin or two at 13QgXZGtXYEY9cnEB9mGuD1ZbXMWirTicg
  21. '''
  22.  
  23. from PIL import Image, ImageTk
  24. from Tkinter import Tk, Entry, Label
  25. from argparse import ArgumentParser
  26. from bs4 import BeautifulSoup
  27. from cStringIO import StringIO
  28. from cookielib import CookieJar
  29. from random import randrange, choice
  30. from time import sleep
  31. from urllib import urlencode
  32. from urllib2 import urlopen, Request, HTTPCookieProcessor, install_opener, build_opener, URLError
  33.  
  34. class InputWindow:
  35.     def __init__(self, container, img=None, p=None):
  36.         root = Tk()
  37.         root.attributes('-topmost', 1)
  38.         hint = '(Enter - submit, Esc - abort)'
  39.         if img is None:
  40.             root.wm_title('Address')
  41.             hint = 'Please enter your Bitcoin address.\n' + hint
  42.         else:
  43.             root.wm_title('Captcha {0:g}'.format(p))
  44.             img = ImageTk.PhotoImage(img)
  45.             root.img_reference = img
  46.         image = Label(root, image=img, text=hint, compound='top')
  47.         image.pack()
  48.         entry = Entry(root)
  49.         entry.bind('<Escape>', lambda _:root.destroy())
  50.         entry.bind('<Return>', lambda _:(container.setdefault(0, (entry.get())), root.destroy()))
  51.         entry.pack()
  52.         entry.focus_set()
  53.         root.update_idletasks()
  54.         xp = (root.winfo_screenwidth() / 2) - (root.winfo_width() / 2) - 8
  55.         yp = (root.winfo_screenheight() / 2) - (root.winfo_height() / 2) - 20
  56.         root.geometry('+%d+%d' % (xp, yp))
  57.         root.mainloop()
  58.  
  59. class PyVisitor:
  60.     def __init__(self, address=None, agentFile=None):
  61.         self.__addr = address
  62.         if not address:
  63.             address = {}
  64.             InputWindow(address)
  65.             if not address.get(0):
  66.                 print 'Aborted by user.'
  67.                 exit(0)
  68.             self.__addr = address[0]
  69.         self.__currentProfit = .0
  70.         self.__currency = ''
  71.         self.__captchaURL = None
  72.         self.__host = 'http://bitvisitor.com/'
  73.         defaultAgent = 'Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.15'
  74.         self.__headers = {'Accept':'text/html,application/xhtml+xml,application/xml',
  75.                           'User-Agent':defaultAgent}
  76.         install_opener(build_opener(HTTPCookieProcessor(CookieJar())))
  77.         if agentFile:
  78.             try:
  79.                 with open(agentFile) as f:
  80.                     self.__headers['User-Agent'] = choice([agent.rstrip() for agent in f])
  81.             except:
  82.                 print 'Using default User-Agent.'
  83.             print 'User-Agent:', self.__headers['User-Agent']
  84.         print 'Bitcoin address:', self.__addr
  85.  
  86.     def __getCaptchaURL(self, soup):
  87.         captchaImg = soup.find('img', id='siimage')
  88.         if not captchaImg:
  89.             return
  90.         earning = soup.find('h1', 'page-header').contents[1].split()
  91.         self.__currentProfit = float(earning[0])
  92.         self.__currency = earning[1]
  93.         self.__captchaURL = self.__host + captchaImg['src'].lstrip('./')
  94.         return self.__captchaURL
  95.  
  96.     def __wait(self, soup):
  97.         siteFrame = soup.find('iframe', id='mlsFrame')
  98.         if not siteFrame: return
  99.         print 'Visiting', siteFrame['src']
  100.         print 'Getting {0:g} {1} in'.format(self.__currentProfit, self.__currency),
  101.         for i in range(5, 0, -1):
  102.             print i,
  103.             sleep(60)
  104.         print
  105.         sleep(randrange(1, 10))  # just to be sure ;)
  106.  
  107.     def visit(self):
  108.         req = Request(self.__host, None, self.__headers)
  109.         res = urlopen(req)  # set session cookie
  110.         if 'abuse' in res.geturl():
  111.             print 'ERROR: The IP address was deemed suspicious.'
  112.             return
  113.         # Please do not change the address in the next line. It costs you nothing, but it helps me.
  114.         params = urlencode({'addr':self.__addr, 'ref':'1Mj8JCYJDjDKMjmvsTrpVPap4BvFyGZVCm'})
  115.         url = self.__host + 'next.php'
  116.         self.__headers['Referer'] = url
  117.         req = Request(url, params, self.__headers)
  118.         while True:
  119.             res = urlopen(req)
  120.             if 'abuse' in res.geturl():
  121.                 print 'ERROR: The IP address was deemed suspicious.'
  122.                 break
  123.             soup = BeautifulSoup(res.read())
  124.             if not self.__getCaptchaURL(soup): break
  125.             a = None
  126.             while not a:
  127.                 captcha = {}
  128.                 InputWindow(captcha, Image.open(StringIO(urlopen(self.__captchaURL).read())), self.__currentProfit)
  129.                 if not captcha.get(0):
  130.                     print 'Aborted by user.'
  131.                     break
  132.                 cParams = urlencode({'ct_captcha':captcha[0], 'addr':self.__addr})
  133.                 soup = BeautifulSoup(urlopen(Request(url, cParams, self.__headers)).read())
  134.                 form = soup.find('form', action='next.php')
  135.                 if not form:
  136.                     message = soup.get_text()
  137.                     if 'Incorrect' in message: continue
  138.                     print message
  139.                     break
  140.                 a = form.find('input', {'name':'a'})['value']
  141.                 t = form.find('input', {'name':'t'})['value']
  142.                 if a and t:
  143.                     break
  144.             if not a:  # aborted by user or site error
  145.                 break
  146.             self.__wait(soup)
  147.             nParams = urlencode({'addr':self.__addr, 'a':a, 't':t})
  148.             res = urlopen(Request(url, nParams, self.__headers))
  149.             if not res:
  150.                 break
  151.             print 'Earned {0:g} {1}'.format(self.__currentProfit, self.__currency)
  152.  
  153. def main():
  154.     parser = ArgumentParser()
  155.     parser.add_argument('-u', '--user-agents', metavar='path',
  156.                         help='A path to a file containing a user-agent on each line.')
  157.     parser.add_argument('-a', '--address', metavar='address',
  158.                         help='Your bitcoin address. If omitted, you will be prompted.')
  159.     ns = parser.parse_args()
  160.     try:
  161.         PyVisitor(ns.address, ns.user_agents).visit()
  162.     except URLError as e:
  163.         print str(e)
  164.  
  165. if __name__ == "__main__":
  166.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement