Login

rss news

Author:
montao
Posted:
November 28, 2009
Language:
Python
Version:
1.1
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. Template tag - list punctuation for a list of items by shapiromatron 11 months, 2 weeks ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 11 months, 3 weeks ago
  3. Serializer factory with Django Rest Framework by julio 1 year, 6 months ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 7 months ago
  5. Help text hyperlinks by sa2812 1 year, 7 months ago

Comments

Please login first before commenting.