Esempio n. 1
0
def main():
    # Bridge the gap between sync and async
    future = asyncio.Task(crawl_async(argv[1], int(argv[2]), int(argv[3])))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(future)
    loop.close()

    result = future.result()
    print_top_words(result)
Esempio n. 2
0
def main():
    # Bridge the gap between sync and async
    future = asyncio.Task(crawl_async(argv[1], int(argv[2]), int(argv[3])))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(future)
    loop.close()

    result = future.result()
    print_top_words(result)
Esempio n. 3
0
    def handle_request(self, message, payload):
        response = Response(self.writer, 200)
        response.add_header('Content-Type', 'text/html')
        response.send_headers()

        if message.method == 'GET':
            response.write(MY_FORM.encode('utf-8'))
        elif message.method == 'POST':
            data = yield from payload.read()
            data = data.decode('utf-8')
            url = dict(parse_qsl(data)).get('url')
            result = yield from crawl_async(url, 1, 1)
            response.write(b'<pre>')
            top_words = get_global_words(result)
            message = get_top_words_message(top_words)
            response.write(escape(message).encode('utf-8'))
            response.write(b'</pre>')
        else:
            response.write('Bad method')

        response.write_eof()