Cookbook: HTTPClientThe web client support in Kamaelia currently comes in two forms:
The Single Shot Web ClientAs you can see, this component takes a single argument, goes off, fetches it, and spits it out of it's main outbox "outbox". If we run this, we get the following:from Kamaelia.Chassis.Pipeline import Pipeline As you can see this is not as simple an object as you might have expected. Rather than just being passed the data, you are passed an object. You're not really expected to use this, but it is useful to know about.~> ./test.py The Reusable Web Client NOTE: The URLs passed over to the SimpleHTTPClient MUST NOT include a newline, or else you will be left wondering why your code doesn't work. This is why this example ensures that the ConsoleReader strips the carriage return from the end of line! from Kamaelia.Chassis.Pipeline import Pipeline As you can see, this time we have a console reader - where we're expected to type URLs. These URLs are passed to the SimpleHTTPClient which goes off, grabs the URLs and dumps them out of it's main outbox "outbox". If we runs this, we get the following: As you can see, this version of the system simple sends the body of the HTTP response to its main outbox "outbox". If you want more information (such as response headers etc), you have to use these components differently. However as basic examples hopefully these are sufficient :-)~> ./PipedHTTP.py Feed Fetching, Parsing, Printing, Displaying Note: This example can be simplified - see Cookbook PureTransformer This is a more substantial, but relatively basic example. If we run this, we get the following:import feedparser It's probably worth noting at this point that you can pretty much use this then in a similar way to the way Kamaelia Macro handles multiplexes EIT information and uses that to trigger events (such as finishing a transcoding session).~> ./PipedFeedFetcher.py -- Michael, December 2006 |
Kamaelia
is an open source project originated from and guided by BBC
Research. For more information browse the site or get in
contact.
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved