view pyikriam/lazy/www/__init__.py @ 104:b369fe3c1992

fixed typo and war counting
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Wed, 29 Oct 2008 15:08:34 +0800
parents a4c364888197
children 60c4b4b78a01
line wrap: on
line source

# -*- coding: utf-8 -*-
#
# Copyright 2008 Hsin Yi, Chen
"""
    [Note] the project is not available yet.

    A web page fetcing tool chain that has a JQuery-like selector and supports chain working.
    
    Here is an exmaple can show the the main idea, To restrive a content you want
    in a div box in a web page, and then post and restrive next content in the other
    web page with the param you just maked from the content in first restriving.
    finally, storage the production.
    
    def func(s):
        return {'msg':s}
    
    try:
        c("http://example.tw/").get().find("#id > div") \
            .build_param( func ).post_to("http://example2.com") \
            .save_as('hellow.html')
    except:
        pass
        
    more complex example
        
    try:
        c("http://example.tw/").retry(4, '5m').get() \
            .find("#id > div"). \
            .build_param( func ).post_to("http://example2.com") \
            .save_as('hellow.html') \
            .end().find("#id2 > img").download('pretty-%s.jpg'). \
            tar_and_zip("pretty_girl.tar.gz")
    except NotFound:
        print "the web page is not found."
    except NoPermissionTosave:
        print "the files can not be save with incorrect permission."
    else:
        print "unknow error."
"""
from lazy.www.work import WorkFlow
from lazy.www.work.fetch import Fetcher, install_opener
from lazy.www.core import SemiProduct

def c(url):
    """
    connect to a web apge
    
    >>> c('http://localhost:8080').get().worker.working_product.content
    'It works!!\\n'
    
    >>> c('http://localhost:8080').get().find('//text()')
    'It works!!\\n'    
    """
    s= SemiProduct(source=url)    
    w = WorkFlow(Fetcher(s))
    return w

def lz_install(**kwds):
    if('opener' == kwds.get('name')):
       install_opener(kwds.get('cookiefile'))

if __name__ == '__main__':
    import doctest
    doctest.testmod()