Skip to content

Instantly share code, notes, and snippets.

@Malarne
Created January 8, 2019 11:03
Show Gist options
  • Save Malarne/39f9462c39255fcdc83bf229a862b120 to your computer and use it in GitHub Desktop.
Save Malarne/39f9462c39255fcdc83bf229a862b120 to your computer and use it in GitHub Desktop.
from aiohttp import web
import asyncio
class WebTest:
def __init__(self, bot):
self.app = web.Application()
self.bot = bot
self.port = 8080
self.handler = None
self.runner = None
def _http_handle(self, request):
name = request.math.info.get('name', 'Anonymous')
text = f"Hello, {name}"
return web.Response(text=text, content_type='text/html')
def __unload(self):
self.bot.loop.create_task(self.runner.cleanup())
async def make_webserver(self):
async def page(request):
body = "Hello world !"
return web.Response(text=body, content_type='text/html')
await asyncio.sleep(10)
self.app.router.add_get('/', page)
self.runner = web.AppRunner(self.app)
await self.runner.setup()
self.handler = web.TCPSite(self.runner, 'localhost', self.port)
await self.handler.start()
print('WebTest started ...')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment