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
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)