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 ''+rss1_text+'' except IndexError,e: return '' except urlfetch.Error, e: pass register.filter(news)