Ejemplo n.º 1
0
import feedparser

rss = PyRSS2Gen.RSS2(
    "This is a test",
    "http://www.dalkescientific.com/",
    "To be or not to be.  That is the question.",

    language = "en-US",
    copyright = "Copyright (c) 2003, by me",
    managingEditor = "here@there (everywhere)",
    webMaster = "Spider Man",
    pubDate = datetime.datetime(2000, 11, 20, 23, 45, 19),
    lastBuildDate = datetime.datetime(2001, 12, 25, 22, 51, 49),
    categories = ["live", "love", "larf", "loaf"],

    cloud = PyRSS2Gen.Cloud("rpc.sys.com", 80, "/RPC2", "pingMe", "soap"),
                       
    ttl = 10,
    image = PyRSS2Gen.Image("http://there/", "THERE!", "link?",
                            25, 94, "some description"),
    rating = "For all audiences",

    textInput = PyRSS2Gen.TextInput("Qwerty", "Shrdlu", "Etaoin",
                                    "http://some/link"),
    skipDays = PyRSS2Gen.SkipDays(["Monday", "Thursday"]),
    skipHours = PyRSS2Gen.SkipHours([0, 5, 22]),

    items = [PyRSS2Gen.RSSItem(
                "Chapter 1", "http://xe.com/",
                "How to convert money.",
                author = "x@xe",
Ejemplo n.º 2
0
def generateRSS( rootNode, indent=2 ):
    """Generate an OPML/XML tree from OutlineNode rootNode.
    
    parameters:
     filepath - unused since file writing has been factored out
     indent   - if > 0 indent with indent spaces per level
    return
     etree.Element of rootNode
    """

    valid_RSSChannel = ( "title", "link", "description", "language",
            "copyright", "managingEditor", "webMaster", "pubDate",
            "lastBuildDate", "categories", "generator", "docs",
            "cloud", "ttl", "image", "rating", "textInput",
            "skipHours", "skipDays", "items")

    valid_RSSItems = ( "title", "link", "description", "author",
            "categories", "comments", "enclosure", "guid",
            "pubDate", "source" )

    backTranslator = {
        'subtitle': 'description',
        'title': 'title',
        'published': 'pubDate',
        'id': 'guid'
    }

    now = str(datetime.datetime.now())
    now = now[:19]
    now = now.replace(" ", "_")

    # unused
    creator = CactusVersion.document_creator + " on %s." % (now,)

    # defaults
    head_d = {
        'title': "No Channel Title",
        'description': "No Channel description.",
        'link':  ""}

    headOP = rootNode.findFirstChildWithName_( "head" )

    if headOP:
        for headsub in headOP.children:
            name = headsub.name
            name = backTranslator.get(name, name)
            if name in valid_RSSChannel:
                value = headsub.getValueDict()
                if name == 'cloud':
                    cloud = PyRSS2Gen.Cloud(
                            value.get('domain', ""),
                            value.get('port', ""),
                            value.get('path', ""),
                            value.get('registerProcedure', ""),
                            value.get('protocol', ""))
                    head_d[ 'cloud' ] = cloud
                elif name == 'image':
                    image = PyRSS2Gen.Image(
                            value.get('href', ""),
                            value.get('title', ""),
                            value.get('link', ""),
                            value.get('width', None),
                            value.get('height', None),
                            value.get('description', None))
                    head_d[ 'image' ] = image

                else:
                    if len(value) == 1:
                        head_d[name] = value.values()[0]
                    else:
                        
                        head_d[name] = value
        print "HEAD:"
        pp(head_d)
    body_l = []
    bodyOP = rootNode.findFirstChildWithName_( "body" )

    if bodyOP:
        for bodysub in bodyOP.children:
            name = bodysub.name
            value = bodysub.getValueDict()
            d = {'title': "No Item Title",
                 'description': "No Item description."}

            for key in value:
                v = value[key]
                k = backTranslator.get(key, key)
                if k == "summary":
                    k = "description"
                if k in valid_RSSItems:

                    if k == 'enclosure':
                        url, rest = value[key].split('<<<')
                        length, type_ = rest.split(';', 1)
                        try:
                            length = int(length)
                        except ValueError, err:
                            if kwlog:
                                print "BOGUS ENCLOSURE LENGTH: %s" % repr(length)
                            length = 0
                        enc = PyRSS2Gen.Enclosure( url, length, type_)
                        d[k] = enc
                    else:
                        # TODO: check for type here; dicts and lists may be bad
                        d[ k ] = v #value[key]
                        if type(d[ k ]) in (list, dict, tuple):
                            print "\ngenerateRSS() type error.\n"
                        
            #print "ITEM:"
            #pp( d )
            body_l.append( PyRSS2Gen.RSSItem( **d ) )