# Path: src/presenters/models.py
# class Platform(models.Model):
#     name = models.CharField(max_length=50)
#     url = models.CharField(max_length=50)
#     intro = models.TextField()
#     logo = models.ImageField(upload_to='platform_logos', blank=True)
# 
#     login_param = models.TextField()
#     fetch_status = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return self.name
# 
# class Presenter(models.Model):
#     game = models.ForeignKey('Game', default=get_default_game)
#     platform = models.ForeignKey('Platform')
#     id_in_platform = models.IntegerField(default=0)
#     tag = models.ManyToManyField('Tag', blank=True)
#     nickname = models.CharField(max_length=50)
#     introduce = models.TextField()
#     room_url = models.CharField(max_length=255, blank=True)
#     gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M')
#     avatar_url = models.CharField(max_length=255, blank=True)
# 
#     join_date = models.DateField(auto_now_add=True)
# 
#     invalid = models.BooleanField(default=True)
# 
#     def __unicode__(self):
#         return self.nickname
# 
# class Game(models.Model):
#     name = models.CharField(max_length=50)
# 
#     def __unicode__(self):
#         return self.name


from django.shortcuts import render
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, Http404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Count
from .models import Platform, Presenter, Game
from haystack.query import SearchQuerySet
import urllib, urllib2, cookielib, json
import time
import logging

        result.append(item)

    logger.info("\tfetch presenter data from longzhu successful")
    return result

def _fetch_longzhu_room_detail(plu_id, plu_login_sessid, domain):
    # 获得房间详细信息(观众人数……)
    room_info_url = 'http://star.apicdn.plu.cn/room/GetInfoJsonp?domain=%s' % domain
    _headers = {
        "Cookie": 'p1u_id=%s; PLULOGINSESSID=%s' % (plu_id, plu_login_sessid)
    }
    req = urllib2.Request(room_info_url, headers=_headers)
    response = urllib2.urlopen(req)
    return json.loads(response.read())

def fetch(request):
    logger.info('fetch presenter data start')

    result = []
    result.extend(fetch_douyu(request))
    result.extend(fetch_huya(request))
    result.extend(fetch_zhanqi(request))
    result.extend(fetch_longzhu(request))
    result.extend(fetch_panda(request,status=2))
    result.extend(fetch_panda(request,status=3))

    for item in result:
        try:
            p = get_object_or_404(

# Path: src/presenters/models.py
# class Platform(models.Model):
#     name = models.CharField(max_length=50)
#     url = models.CharField(max_length=50)
#     intro = models.TextField()
#     logo = models.ImageField(upload_to='platform_logos', blank=True)
# 
#     login_param = models.TextField()
#     fetch_status = models.BooleanField(default=False)
# 
#     def __unicode__(self):
#         return self.name
# 
# class Presenter(models.Model):
#     game = models.ForeignKey('Game', default=get_default_game)
#     platform = models.ForeignKey('Platform')
#     id_in_platform = models.IntegerField(default=0)
#     tag = models.ManyToManyField('Tag', blank=True)
#     nickname = models.CharField(max_length=50)
#     introduce = models.TextField()
#     room_url = models.CharField(max_length=255, blank=True)
#     gender = models.CharField(max_length=1, choices=GENDER_CHOICES, default='M')
#     avatar_url = models.CharField(max_length=255, blank=True)
# 
#     join_date = models.DateField(auto_now_add=True)
# 
#     invalid = models.BooleanField(default=True)
# 
#     def __unicode__(self):
#         return self.nickname
# 
# class Game(models.Model):
#     name = models.CharField(max_length=50)
# 
#     def __unicode__(self):
#         return self.name


# Path: src/presenters/views.py
from django.shortcuts import render
from django.shortcuts import get_object_or_404
from django.http import HttpResponse, Http404
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.db.models import Count
from .models import Platform, Presenter, Game
from haystack.query import SearchQuerySet
import urllib, urllib2, cookielib, json
import time
import logging


        result.append(item)

    logger.info("\tfetch presenter data from longzhu successful")
    return result

def _fetch_longzhu_room_detail(plu_id, plu_login_sessid, domain):
    # 获得房间详细信息(观众人数……)
    room_info_url = 'http://star.apicdn.plu.cn/room/GetInfoJsonp?domain=%s' % domain
    _headers = {
        "Cookie": 'p1u_id=%s; PLULOGINSESSID=%s' % (plu_id, plu_login_sessid)
    }
    req = urllib2.Request(room_info_url, headers=_headers)
    response = urllib2.urlopen(req)
    return json.loads(response.read())

def fetch(request):
    logger.info('fetch presenter data start')

    result = []
    result.extend(fetch_douyu(request))
    result.extend(fetch_huya(request))
    result.extend(fetch_zhanqi(request))
    result.extend(fetch_longzhu(request))
    result.extend(fetch_panda(request,status=2))
    result.extend(fetch_panda(request,status=3))

    for item in result:
        try:
            p = get_object_or_404(

                Presenter, 