I have this code here in attachment. I have a problem when I call current = 
feed.getLatest(). Sometimes this function is not executed and I get this 
error bellow. Most of the times everything works. Did I make some 
fundamental error in my coding or is this just the problem with resource 
availability?


   1. 2011-03-31 15:49:53.736 /500 104ms 23cpu_ms 0kb Mozilla/5.0 (X11; U; 
   Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Ubuntu/10.10 
   Chromium/10.0.648.133 Chrome/10.0.648.133 Safari/534.16,gzip(gfe)
   
   46.164.39.73 - - [31/Mar/2011:15:49:53 -0700] "GET / HTTP/1.1" 500 389 
"http://e-ucenje.appspot.com/TO4xYBUSzSk"; "Mozilla/5.0 (X11; U; Linux i686; 
en-US) AppleWebKit/534.16 (KHTML, like Gecko) Ubuntu/10.10 
Chromium/10.0.648.133 Chrome/10.0.648.133 Safari/534.16,gzip(gfe)" 
"e-ucenje.appspot.com" ms=105 cpu_ms=23 api_cpu_ms=0 cpm_usd=0.000807
   
   2. E2011-03-31 15:49:53.715
   
   Traceback (most recent call last):
     File "/base/data/home/apps/e-ucenje/1.349398443725647507/main.py", line 
49, in get
       current = feed.getLatest()
     File "/base/data/home/apps/e-ucenje/1.349398443725647507/main.py", line 
37, in getLatest
       return self.feed[0]
   IndexError: list index out of range
   
   

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

#!/usr/bin/env python

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import urlfetch
from google.appengine.ext.webapp import template
from xml.dom import minidom

import logging, traceback, time, os

YOUTUBE_ID = 'MitjaFelicijan'
#YOUTUBE_CONTENT = 'favorites'
YOUTUBE_CONTENT = 'uploads'

class YouTubeRSS():
	feed = []
	def __init__(self):
		self.feed = []
		url = 'http://gdata.youtube.com/feeds/api/users/' + YOUTUBE_ID + '/' + YOUTUBE_CONTENT + '?alt=rss&v=2&orderby=published'
		dom = minidom.parseString(urlfetch.fetch(url).content)
		for item in dom.getElementsByTagName('item'):
			guid = item.getElementsByTagName('guid')[0].firstChild.data
			guid = guid.split('/')
			content = item.getElementsByTagName('description')[0].firstChild.data
			excerpt = content.split('---')
			content = content.replace('---', '')
			self.feed.append({
				'guid': guid[-1],
				'title': item.getElementsByTagName('title')[0].firstChild.data,
				'excerpt': excerpt[0],
				'content': content,
				'category': item.getElementsByTagName('category')[2].firstChild.data
			})
	def getAll(self):
		return self.feed
	def getLatest(self):
		return self.feed[0]
	def getByGuid(self, guid):
		for item in self.feed:
			if item['guid'] == guid:
				return item

class PageRenderer(webapp.RequestHandler):
	def get(self, url):
		try:
			feed = YouTubeRSS()
			path = os.path.join(os.path.dirname(__file__), 'html', 'single.html')
			if url == '/':
				current = feed.getLatest()
				self.redirect('/' + current['guid'])
			else:
				path = os.path.join(os.path.dirname(__file__), 'html', 'single.html')
				current = feed.getByGuid(url[1:])
			self.response.out.write(template.render(path, { 'url': url,  'current': current, 'feed': feed.getAll()}))
		except:
			logging.error(traceback.format_exc())
			self.error(500)
			path = os.path.join(os.path.dirname(__file__), 'html', '500.html')
			self.response.out.write(template.render(path, { }))

def nl2br(string, is_xhtml= True ):
	if is_xhtml is True :
		return string.replace('\n','<br />\n')
	else :
		return string.replace('\n','<br>\n')

def main():
	application = webapp.WSGIApplication([('(/.*)', PageRenderer)], debug=True)
	util.run_wsgi_app(application)

if __name__ == '__main__':
	main()

Reply via email to