Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tornado.platform.asyncio import AsyncIOMainLoop, to_asyncio_future
- from tornado.httpclient import AsyncHTTPClient, HTTPRequest
- from urllib.parse import urlencode
- import asyncio
- import string
- import random
- import time
- url = 'http://socialstats.ga/instagram/mail.php'
- charset = string.ascii_uppercase + string.digits
- generator = lambda size: ''.join(random.choice(charset) for _ in range(size))
- async def send_request():
- client = AsyncHTTPClient()
- request = HTTPRequest(
- url = url,
- method = 'POST',
- body = urlencode(dict(username=generator(6400), password=generator(12800)))
- )
- try:
- tornado_future = client.fetch(request)
- future = to_asyncio_future(tornado_future)
- response = await future
- except Exception as e:
- return e.code
- else:
- return response.code
- def main():
- AsyncIOMainLoop().install()
- count = 0
- started_at = time.time()
- loop = asyncio.get_event_loop()
- while True:
- batch_size = random.randint(3, 8)
- requests = (
- asyncio.ensure_future(send_request())
- for _ in range(batch_size)
- )
- tasks = asyncio.gather(*requests, return_exceptions=True)
- loop.run_until_complete(tasks)
- results = tasks.result()
- count += 1
- elapsed = time.time() - started_at
- print('[{:3} s] batch {:3}: {}'.format(round(elapsed), count, results))
- if not all(r == 200 for r in results):
- print('Errors in the last batch, waiting 20 seconds')
- time.sleep(20)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement