# 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
        'game_list': game_list,
    }

    return render(request, 'presenters/index.html', context)

def detail(request, presenter_id):
    p = get_object_or_404(Presenter, id=presenter_id)
    context = {
        'presenter': p,
    }
    return render(request, 'presenters/detail.html', context)

def about(request):
    # print dir(request)
    return render(request, 'presenters/about.html')

def feedback(request):
    return render(request, 'presenters/feedback.html')

def fetch_huya(requst):
    # 虎牙直播
    # 貌似没有加密措施，登录后会得到一个uid
    result = []
    platform = Platform.objects.get(name=u'虎牙')
    try:
        params = json.loads(platform.login_param)
    except:
        logger.error("\tfetch presenter data from huya failed, error message: {%s}", '无效的fetch参数')
        return result


# 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

        'game_list': game_list,
    }

    return render(request, 'presenters/index.html', context)

def detail(request, presenter_id):
    p = get_object_or_404(Presenter, id=presenter_id)
    context = {
        'presenter': p,
    }
    return render(request, 'presenters/detail.html', context)

def about(request):
    # print dir(request)
    return render(request, 'presenters/about.html')

def feedback(request):
    return render(request, 'presenters/feedback.html')

def fetch_huya(requst):
    # 虎牙直播
    # 貌似没有加密措施，登录后会得到一个uid
    result = []
    platform = Platform.objects.get(name=u'虎牙')
    try:
        params = json.loads(platform.login_param)
    except:
        logger.error("\tfetch presenter data from huya failed, error message: {%s}", '无效的fetch参数')
        return result


    huya_url = 'http://phone.huya.com/api/acts/reserved?uid=%s' % params['uid']