Last active
October 18, 2018 09:06
-
-
Save MikeLing/f5098de1f043070f8ab90d8b70c7697f to your computer and use it in GitHub Desktop.
mutiple request version for snapper.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import time | |
import csv | |
import asyncio | |
import aiohttp | |
data = [] | |
tasks = [] | |
results = [] | |
with open("sample-image-links.csv") as f: | |
reader = csv.reader(f) | |
for row in reader: | |
data.append(row[0]) | |
#payload2 = data[334:666] | |
#payload3 = data[667:1000] | |
#respond = map(tester, payload1) | |
#print (respond.json()) | |
start_time = time.time() | |
async def get(payload): | |
print('GET: ', payload) | |
async with aiohttp.ClientSession() as session: | |
async with session.get('http://104.197.205.154:1080/evaluation', data=json.dumps(payload)) as response: | |
results.append(await response.json()) | |
loop = asyncio.get_event_loop() | |
offset = 0 | |
while offset < 1000: | |
payload = data[offset:offset+100] | |
offset = offset + 100 | |
for i in range(0, len(payload), 10): | |
temp = [payload[i], payload[i+1], payload[i+2],payload[i+3],payload[i+4],payload[i+5],payload[i+6],payload[i+7],payload[i+8],payload[i+9]] | |
tasks = tasks + [asyncio.ensure_future(get(temp))] | |
loop.run_until_complete(asyncio.wait(tasks)) | |
print (results) | |
print (time.time() - start_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment