Пример #1
0
def test_fnews():
    import filter_content as f_n
    import model
    f = open("sample.html")
    try:
        assert f_n.full_html == ''
        assert type(f_n.models) == list
        stack.append("\tfilter_news init pass")
        
        f_n.sethtml("abcdefg1234567")
        assert f_n.full_html == "abcdefg1234567"
        stack.append("\tfilter_news sethtml ok!")
        
        f_n.__gethtml(1)
        f.seek(0, 2)
        assert len(f_n.full_html) == f.tell()
        stack.append("\tfilter_news gethtml")
        
        f_p = f_n.MyParser()
        out = f_p.output()
        stack.append("\tfilter_news model empty")
        #stack.append("%d == %d" %( len(f_p._listRes), f_p._resCount))
        
        assert len(f_p._listRes) == f_p._resCount
        stack.append("\tfilter_news output store result")
        assert len(f_p.result) == len(f_p._listRes)
        stack.append("\tfilter_news output generate result")
        f_p.debug(out)
        
    except:
        raise 
    finally:
        f.close()    
Пример #2
0
def main():
    # get html page
    #data = fetch.page(debug=True)
    data = fetch.page()
    
    print "Need download all the available image?"
    save_src = raw_input('>[n]')
    
    # get the useful data
    filter_content.sethtml(data)
    kparser = filter_content.MyParser()
    output = kparser.output()
    #kparser.debug(output)
   
    # display the result
    for post in output:
        if len(post) > 2: # have img
            #print post[1], post[2]
            # save src
            if save_src == 'y' or save_src == 'Y':
                t = downloadThread(post[1], 1)
                t.start()
            else:
                """ A more UX way """
                try:
                    from PIL import ImageFile
                except ImportError:
                    print "Sorry for you can't enjoy this"
                    print "You may need to install the PIL library"
                    print "use the following command:"
                    print "pip install PIL"
                else:
                    # view thumb:
                    p = ImageFile.Parser()
                    data = (fetch.img(post[1]))
                    if data:
                        p.feed(data)
                        im = p.close()
                        im.show()
                        # ask to save the source
                        print "Do you want to save the source?"
                        answer = raw_input('>')
                        if answer == 'y' or answer == 'Y':
                            t = downloadThread(post[1], 1)
                            t.start()
                    else:
                        p.close()