Skip to content

Instantly share code, notes, and snippets.

@seemethere
Created April 16, 2017 17:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seemethere/631093a0990b4aa31e375061b60e9e4d to your computer and use it in GitHub Desktop.
Save seemethere/631093a0990b4aa31e375061b60e9e4d to your computer and use it in GitHub Desktop.
import asyncio
import aiohttp
BASE_URL = 'https://josephg.com/sp/edit'
HEADERS = {
'Origin': 'https://josephg.com',
'User-Agent': ('Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/57.0.2987.133 Mobile Safari/537.36'),
'Referer': 'https://josephg.com/sp/',
}
async def color_square(x, y, color, session):
async with session.post(
BASE_URL, headers=HEADERS,
params={'x': x, 'y': y, 'c': color}) as resp:
status_code = resp.status
success = 'SUCCESS' if status_code == 200 else 'FAILED'
print(f'{success} colored square @ ({x}, {y}) with color {color}')
async def main(coords, color):
async with aiohttp.ClientSession() as session:
coros = [color_square(x, y, color, session) for x, y in coords]
await asyncio.wait(coros)
loop = asyncio.get_event_loop()
coords = [(x, y) for x, y in zip(range(20, 40), range(0, 30))]
loop.run_until_complete(main(coords, 0))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment