Login

rss news

Author:
montao
Posted:
November 28, 2009
Language:
Python
Version:
1.1
Tags:
rss google app gae engine news
Score:
-1 (after 1 ratings)

publish tldrelative rss news exampled web.montao.com.br/li

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def news(n):#eg {{a|news|truncatewords_html:8|fix_ampersands}}
    url = os.environ.get('HTTP_HOST') if os.environ.get('HTTP_HOST') else os.environ['SERVER_NAME']
    tld = url[url.rfind('.'):]    
    try:        
        if url == 'localhost:8080':
            result = urlfetch.fetch('http://news.google.se/?output=rss')    
        elif tld != '.com' and tld != '.se' and tld != '.cl' :
            result = urlfetch.fetch('http://news.google.com'+tld+'/?output=rss') 
        else:        
            result = urlfetch.fetch('http://news.google.com/?output=rss')        
        if result.status_code == 200:
            dom = minidom.parseString(result.content)
            item_node = dom.getElementsByTagName("item")
            try:
                random_1=random.choice(item_node)
                rss1_link = random_1.childNodes[1].firstChild.data
                rss1_text = random_1.childNodes[0].firstChild.data
                return '<a href="'+rss1_link+'">'+rss1_text+'</a>'
            except IndexError,e:
                return ''
    except urlfetch.Error, e: 
        pass            
register.filter(news)

More like this

  1. Parsed RSS into template var by bram 6 years, 9 months ago
  2. Deli.cio.us rss template tag by aaloy 6 years ago
  3. Feed Reader Inclusion Tag with Caching by baumer1122 7 years, 8 months ago
  4. Allow template tags in a Flatpage's content by kylefox 6 years, 9 months ago
  5. twitter_status by zodman 6 years, 7 months ago

Comments

Please login first before commenting.