Пример #1
0
    def on_go_clicked(self, button):
        print 'go clicked, lets start'
        url = self.entry.get_text()

        def parse(data):
            print 'parsing data'
            p = rss.Parser()
            p.load_from_data(data, len(data))
            d = p.get_document()
            return d.get_items()

        def build(items):
            print 'building html'
            return ''.join([
                '<h1>%s</h1><p>%s</p>' % (i.props.title, i.props.description)
                for i in items])

        task = gtask.Task(lambda: urllib.urlopen(url).read())
        task.add_callback(lambda data: gtask.Task(parse, data))
        task.add_callback(lambda items: gtask.Task(build, items))
        task.add_callback(lambda data: self.webview.load_html_string(data, url))
        gtask.scheduler_get_default().schedule(task)
Пример #2
0
#!/usr/bin/env python

import gtask
import urllib
import gtk
import rss

def get_content(url):
    return urllib.urlopen(url).read()

def parse_content(content):
    p = rss.Parser()
    p.load_from_data(content, len(content))
    doc = p.get_document()
    items = doc.get_items()
    return items

def print_items(items):
    for item in items:
        print item.props.title

t = gtask.Task(get_content, 'http://planet.gnome.org/atom.xml')
t.add_callback(lambda c: gtask.Task(parse_content, c))
#t.add_callback(parse_content)
t.add_callback(print_items)
t.add_callback(lambda _: gtk.main_quit())

gtask.scheduler_get_default().schedule(t)
gtk.main()