Untitled


SUBMITTED BY: Guest

DATE: Oct. 23, 2013, 9:20 p.m.

FORMAT: Text only

SIZE: 7.8 kB

HITS: 1119

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

comments powered by Disqus