rss news

 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. ImageField for Google App Engine by davepeck 3 years, 6 months ago
  2. Google AppEngine Login Decorator by cmcavoy 5 years, 1 month ago
  3. Allow template tags in a Flatpage's content by kylefox 4 years, 10 months ago
  4. Template tag for compressed CSS & JS (GAE version) by jeffar 4 years, 10 months ago
  5. @url decorator - getting rid of urlpatterns by southern_sun 5 years, 8 months ago

Comments

(Forgotten your password?)