Permalink
Browse files

youtube_feed works

  • Loading branch information...
1 parent 0b2e90d commit b58874666e3133c1dd80d8e45cec6582431f16ab Matvey Maslov committed Jul 30, 2011
Showing with 15 additions and 10 deletions.
  1. +11 −2 profiles/views.py
  2. +4 −8 sources/youtube.py
View
@@ -1,7 +1,16 @@
from django.shortcuts import render
+from django.http import HttpResponseRedirect, HttpResponse
+
import json
+from sources import youtube
+
+class ObjectEncoder(json.JSONEncoder):
+ def default(self, obj):
+ if hasattr(obj, '__json__'):
+ return obj.__json__()
+ return dict((k, v) for k, v in obj.__dict__.items() if not k.startswith("_"))
def start(request):
return render(request, 'profiles/start.html')
@@ -12,5 +21,5 @@ def registration(request):
def youtube_feed(request):
- username = request.POST['username']
- return json.dumps([video for video in youtube.list_videos(username)])
+ username = request.GET['username']
+ return HttpResponse(json.dumps(youtube.list_videos(username), cls=ObjectEncoder))
View
@@ -10,21 +10,17 @@ def atom_datetime(atom_date):
class YoutubeVideo(object):
def __init__(self, entry):
- self.entry = entry
+ self.title = entry.title.text
+ self.thumbnails = entry.media.thumbnail
# def __getattr__(self, attr):
# value = getattr(self.entry, attr)
# if isinstance(value, atom.Date):
# return datetime.datetime.strptime(value.text, '%Y-%m-%dT%H:%M:%S.%fZ')
# return value.text
- @property
- def title(self):
- return self.entry.title.text
-
- @property
- def thumbnails(self):
- return entry.media.thumbnails
+ def json(self):
+ return self.__dict__
def __repr__(self):
return "YoutubeVideo: '%s'" % self.title

0 comments on commit b588746

Please sign in to comment.