예제 #1
0
def timeline(request, username, child_slug):
    child = get_object_or_404(Child, user__username=username, slug=child_slug)
    children = Child.objects.filter(user__username__exact=username)

    facebook_events = []
    for facebook_source in child.facebook_sources.all():
        events_key = '%s_%s' % (facebook_source.uid, make_uri_title(facebook_source.keywords))
        events = cache.get(events_key)
        if not events:
            events = keywords_present(facebook.list_posts(facebook_source.access_token, first_5=True), comma_split(facebook_source.keywords), facebook.post_text)
            cache.set(events_key, events, 24 * 3600)
        facebook_events.extend(events)

    youtube_source = child.youtube_source
    youtube_events = []
    if youtube_source.usernames:
        for youtube_user in comma_split(youtube_source.usernames):
            youtube_events.extend(keywords_present(youtube.list_videos(youtube_user), comma_split(youtube_source.keywords), lambda video: video.title))


    events = []
    events.extend([FacebookEvent(post) for post in facebook_events])
    events.extend([YouTubeEvent(video) for video in youtube_events])

    events_json = json.dumps(events, cls=ObjectEncoder)
    return render(request, "timeline/timeline.html",
                  { 'events' : events_json, 'children' : children, 'username' : username, 'current_child_slug' : child_slug})
예제 #2
0
파일: views.py 프로젝트: osiloke/FamilyFeed
def timeline(request, username, child_slug):
    child = get_object_or_404(Child, user__username=username, slug=child_slug)
    children = Child.objects.filter(user__username__exact=username)

    facebook_events = []
    for facebook_source in child.facebook_sources.all():
        posts = facebook.list_posts(facebook_source.access_token)
        events = keywords_present(
            posts,
            comma_split(facebook_source.keywords),
            facebook.post_text)
        facebook_events.extend(events)

    youtube_source = child.youtube_source
    youtube_events = []
    if youtube_source.usernames:
        for youtube_user in comma_split(youtube_source.usernames):
            youtube_events.extend(
                keywords_present(youtube.list_videos(youtube_user),
                                 comma_split(youtube_source.keywords),
                                 lambda video: video.title))

    events = [FacebookEvent(post) for post in facebook_events] + \
             [YouTubeEvent(video) for video in youtube_events]
    events_json = json.dumps(events, cls=ObjectEncoder)
    return render(request,
                  'timeline/timeline.html',
                  {'events': events_json,
                   'children': children,
                   'username': username,
                   'current_child_slug': child_slug})
예제 #3
0
파일: views.py 프로젝트: osiloke/FamilyFeed
def start(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect(
            reverse('timeline.views.logged_in', args=[request.user]))
    else:
        videos = [YouTubeEvent(v) for v in youtube.list_videos('vorushin')]
        events = json.dumps(videos, cls=ObjectEncoder)
        return render(request,
                      'timeline/start.html',
                      {'events': events, 'body_class': 'home'})
예제 #4
0
파일: views.py 프로젝트: osiloke/FamilyFeed
def get_youtube_data_ajax(request, username, child_slug):
    keywords = comma_split(request.GET['keywords'])
    usernames = comma_split(request.GET['usernames'])
    youtube_events = []
    for username in usernames:
        youtube_events += youtube.list_videos(username)
    youtube_events = keywords_present(youtube_events,
                                      keywords,
                                      lambda video: video.title)
    youtube_events = [YouTubeEvent(e) for e in youtube_events]
    return render(request,
                  'profiles/youtube_data.html',
                  {'youtube_events': youtube_events})
예제 #5
0
def youtube_feed(request):
    username = request.GET['username']
    return HttpResponse(json.dumps(youtube.list_videos(username),
                                   cls=ObjectEncoder))