Ejemplo n.º 1
0
    async def query(self, sender: Actor):
        try:
            client = kore.httpclient(self._url)
            status, body = await client.get()

            if status == 200:
                dom = parseString(body.decode())
                item = dom.getElementsByTagName('item').item(0)
                title = item.getElementsByTagName('title').item(0)
                text = title.childNodes.item(0).wholeText

                sender.news_update(self._site, text)
                return

        except:
            logging.error(f'Error getting news from {self._site}',
                          exc_info=True)

        sender.news_unavailable(self._site)
Ejemplo n.º 2
0
async def server(req):
    # Create an httpclient.
    client = kore.httpclient("https://kore.io")

    # Do a simple GET request.
    print("firing off request")
    status, body = await client.get()
    print("status: %d, body: '%s'" % (status, body))

    # Reuse and perform another GET request, returning headers too this time.
    status, headers, body = await client.get(return_headers=True)
    print("status: %d, headers: '%s'" % (status, headers))

    # What happens if we post something?
    status, body = await client.post(body=b"hello world")
    print("status: %d, body: '%s'" % (status, body))

    # Add some custom headers to our requests.
    status, body = await client.get(headers={"x-my-header": "async-http"})

    req.response(200, b'async done')
Ejemplo n.º 3
0
async def httpclient(req):
    # Create an httpclient.
    client = kore.httpclient("https://kore.io")

    # Do a simple GET request.
    status, body = await client.get()
    print("status: %d, body: '%s'" % (status, body))

    # Reuse and perform another GET request, returning headers too this time.
    status, headers, body = await client.get(return_headers=True)
    print("status: %d, headers: '%s'" % (status, headers))

    # What happens if we post something?
    status, body = await client.post(body=b"hello world")
    print("status: %d, body: '%s'" % (status, body))

    # Add some custom headers to our requests.
    status, body = await client.get(
        headers={
            "x-my-header": "async-http"
        }
    )

    req.response(200, b'async done')