KamaeliaNuts & Bolts | Components | Tools | Cookbook | Systems
wiki:( guest720923, Dev Console, Index, Recent, Edit )
The web client support in Kamaelia currently comes in two forms:
As 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
from Kamaelia.Protocol.HTTP.HTTPClient import *
from Kamaelia.Util.Console import *
Pipeline(
SingleShotHTTPClient("http://kamaelia.sourceforge.net/Home"),
ConsoleEchoer(),
).run()
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
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
Pipeline(
ConsoleReader(eol=""),
SimpleHTTPClient(),
ConsoleEchoer(),
).run()
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
>>> http://kamaelia.sourceforge.net/Home
>>>
.bodytext {
font-size: 10pt;
...snip...
>>>
If we run this, we get the following:import feedparser
import pprint
import Axon
from Kamaelia.Chassis.Pipeline import Pipeline
from Kamaelia.Util.Console import ConsoleReader, ConsoleEchoer
from Kamaelia.Protocol.HTTP.HTTPClient import SimpleHTTPClient
class Feedparser(Axon.Component.component):
def main(self):
while 1:
while self.dataReady("inbox"):
data = self.recv("inbox")
parseddata = feedparser.parse(data)
self.send(parseddata, "outbox")
if not self.anyReady():
self.pause()
yield 1
class PrettyPrinter(Axon.Component.component):
def main(self):
while 1:
while self.dataReady("inbox"):
data = self.recv("inbox")
prettified = pprint.pformat(data)
self.send(prettified, "outbox")
if not self.anyReady():
self.pause()
yield 1
Pipeline(
ConsoleReader(eol=""),
SimpleHTTPClient(),
Feedparser(),
PrettyPrinter(),
ConsoleEchoer(),
).run()
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
>>> http://kamaelia.sourceforge.net/cgi-bin/blog/feed.cgi
>>> {'bozo': 0,
'encoding': 'utf-8',
'entries': [{'author': u'Michael',
'guidislink': False,
'id': u'http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi?rm=viewpost&nodeid=1158348609.1',
'link': u'http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi?rm=viewpost&nodeid=1158348609.1',
...
'title_detail': {'base': '',
'language': None,
'type': 'text/plain',
'value': u'How do I register?'},
'updated': u'Fri, 29 Sep 2006 12:11:29 +0000',
'updated_parsed': (2006, 9, 29, 12, 11, 29, 4, 272, 0)},
{'author': u'Michael',
'guidislink': False,
'id': u'http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi?rm=viewpost&nodeid=1148942995',
'link': u'http://kamaelia.sourceforge.net/cgi-bin/blog/blog.cgi?rm=viewpost&nodeid=1148942995',
...
'updated': u'Mon, 29 May 2006 22:49:55 +0000',
'updated_parsed': (2006, 5, 29, 22, 49, 55, 0, 149, 0)}],
'feed': {'author': u'email@example.com',
'author_detail': {'name': u'', 'email': u'email@example.com'},
'docs': u'http://blogs.law.harvard.edu/tech/rss',
'generator': u'Kamaelia 0.1',
'generator_detail': {'name': u'Kamaelia 0.1'},
...
'updated': u'Wed, 27 Dec 2006 22:23:49 +0000',
'updated_parsed': (2006, 12, 27, 22, 23, 49, 2, 361, 0)},
'namespaces': {},
'version': 'rss20'}
>>>
Versions: current , 1 , 2 , 3 , 4 , 5 , 6
(C) 2005 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved,
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.