Beispiel #1
0
    def handle(self, *args, **options):
        url = 'http://dev.followkr.com/survey/youtube_api/'
        count = 0
        try:
            Kpop.objects.all().delete()
            r = urllib2.urlopen(url)
            root = json.loads(r.read())
            root.reverse()
            for r in root:
                count = count + 1
#                 print r['title']
#                 print r['url']
#                 print r['thumbnail_url']
#                 print r['rank']
                kpop = Kpop()
                kpop.user = User.objects.get(id=1)
                kpop.media_url = r['thumbnail_url']
#                 kpop.post = u'<center> %s位 ' % r['rank']
                kpop.post = kpop.post + u'<center> %s位 ' % r['rank'] + r['title'] + u'</center>'
                kpop.post = kpop.post + u'<center><iframe width="560" height="315" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe></center>' % r['videoId']
#                 kpop.post = kpop.post + u'<iframe width="320" height="180" src="http://www.youtube.com/embed/%s"></iframe>' % r['videoId']
                kpop.save()
                kpop.date = kpop.date + datetime.timedelta(0,count)
                kpop.save()
                
        except Exception, e:
            print e
Beispiel #2
0
def post(request):
    last_kpop = request.POST.get('last_kpop')
    user = request.user
    csrf_token = unicode(csrf(request)['csrf_token'])
    kpop = Kpop()
    kpop.user = user
    post = request.POST['post']
    post = post.strip()
    if len(post) > 0:
        kpop.post = post[:255]
        kpop.save()
    html = _html_kpops(last_kpop, user, csrf_token)
    return HttpResponse(html)
Beispiel #3
0
def check(request):
    last_kpop = request.GET.get('last_kpop')
    kpop_source = request.GET.get('kpop_source')
    kpops = Kpop.get_kpops_after(last_kpop)
    if kpop_source != 'all':
        kpops = kpops.filter(user__id=kpop_source)
    count = kpops.count()
    return HttpResponse(count)
Beispiel #4
0
def update(request):
    first_kpop = request.GET.get('first_kpop')
    last_kpop = request.GET.get('last_kpop')
    kpop_source = request.GET.get('kpop_source')
    kpops = Kpop.get_kpops().filter(id__range=(last_kpop, first_kpop))
    if kpop_source != 'all':
        kpops = kpops.filter(user__id=kpop_source)
    dump = {}
    for kpop in kpops:
        dump[kpop.pk] = {'likes': kpop.likes, 'comments': kpop.comments}
    data = json.dumps(dump)
    return HttpResponse(data, content_type='application/json')
Beispiel #5
0
def kpops(request):
    all_kpops = Kpop.get_kpops()
    paginator = Paginator(all_kpops, FEEDS_NUM_PAGES)
    kpops = paginator.page(1)
    from_kpop = -1
    if kpops:
        from_kpop = kpops[0].id
    return render(request, 'kpops/kpops.html', {
        'kpops': kpops, 
        'from_kpop': from_kpop, 
        'page': 1,
        })
Beispiel #6
0
def _html_kpops(last_kpop, user, csrf_token, kpop_source='all'):
    kpops = Kpop.get_kpops_after(last_kpop)
    if kpop_source != 'all':
        kpops = kpops.filter(user__id=kpop_source)
    html = u''
    for kpop in kpops:
        html = u'{0}{1}'.format(html, render_to_string('kpops/partial_kpop.html', {
            'kpop': kpop,
            'user': user,
            'csrf_token': csrf_token
            })
        )
    return html
Beispiel #7
0
def load(request):
    from_kpop = request.GET.get('from_kpop')
    page = request.GET.get('page')
    kpop_source = request.GET.get('kpop_source')
    all_kpops = Kpop.get_kpops(from_kpop)
    if kpop_source != 'all':
        all_kpops = all_kpops.filter(user__id=kpop_source)
    paginator = Paginator(all_kpops, FEEDS_NUM_PAGES)
    try:
        kpops = paginator.page(page)
    except PageNotAnInteger:
        return HttpResponseBadRequest()
    except EmptyPage:
        kpops = []
    html = u''
    csrf_token = unicode(csrf(request)['csrf_token'])
    for kpop in kpops:
        html = u'{0}{1}'.format(html, render_to_string('kpops/partial_kpop.html', {
            'kpop': kpop,
            'user': request.user,
            'csrf_token': csrf_token
            })
        )
    return HttpResponse(html)