# Path: app/blog_lab/models.py
# class ProxyUser(BaseModel):
#     token = models.CharField(max_length=64)
#     ip = models.CharField(max_length=20)
#     record = models.CharField(max_length=1000, default='')
# 
#     def __unicode__(self):
#         return self.token
# 
# class Proxy(BaseModel):
#     ip = models.CharField(max_length=30, unique=True)
#     online = models.BooleanField(default=True)
# 
#     def __unicode__(self):
#         return self.ip
# 
# Path: app/blog_log/models.py
# class ReqRecord(BaseModel):
#     uri = models.CharField(max_length=100, default='')
#     ip = models.ForeignKey(AccIP, related_name="records")
# 
#     def __unicode__(self):
#         return self.uri
# 
# class BackLog(BaseModel):
#     content = models.CharField(max_length=50)
#     log_type = models.IntegerField()
#     status = models.BooleanField(default=True)
#     fail_message = models.CharField(max_length=500, default='')
# 
#     def __unicode__(self):
#         return self.content
# 
# Path: app/utils.py
# def datetime_to_string(datetimet, str_format='%Y-%m-%d %H:%M:%S'):
#     if datetimet.tzinfo is None:
#         return datetimet.strftime(str_format)
#     time_str = datetimet.astimezone(timezone.get_current_timezone())
#     return time_str.strftime(str_format)
# 
# def encodejson(status, body):
#     tmpjson={}
#     tmpjson['status'] = status
#     tmpjson['body'] = body
#     return simplejson.dumps(tmpjson)


import datetime
import ujson
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.utils import timezone
from dss.Serializer import serializer
from app.blog_lab.models import ProxyUser, Proxy
from app.blog_log.models import ReqRecord, BackLog
from app.utils import datetime_to_string, encodejson
# -*- coding: utf-8 -*-




# Create your views here.

def proxy(req):
    return render_to_response("proxy.html")


def monitor(req):
    return render_to_response("monitor.html")


def get_lab_info(req):
    body={}
    now = timezone.now()
    start = now - datetime.timedelta(hours=23, minutes=59, seconds=59)
    total_use = ProxyUser.objects.all().count()
    day_req = ReqRecord.objects.filter(uri='/lab/get_proxy/', create_time__gt=start).count()

# Path: app/blog_lab/models.py
# class ProxyUser(BaseModel):
#     token = models.CharField(max_length=64)
#     ip = models.CharField(max_length=20)
#     record = models.CharField(max_length=1000, default='')
# 
#     def __unicode__(self):
#         return self.token
# 
# class Proxy(BaseModel):
#     ip = models.CharField(max_length=30, unique=True)
#     online = models.BooleanField(default=True)
# 
#     def __unicode__(self):
#         return self.ip
# 
# Path: app/blog_log/models.py
# class ReqRecord(BaseModel):
#     uri = models.CharField(max_length=100, default='')
#     ip = models.ForeignKey(AccIP, related_name="records")
# 
#     def __unicode__(self):
#         return self.uri
# 
# class BackLog(BaseModel):
#     content = models.CharField(max_length=50)
#     log_type = models.IntegerField()
#     status = models.BooleanField(default=True)
#     fail_message = models.CharField(max_length=500, default='')
# 
#     def __unicode__(self):
#         return self.content
# 
# Path: app/utils.py
# def datetime_to_string(datetimet, str_format='%Y-%m-%d %H:%M:%S'):
#     if datetimet.tzinfo is None:
#         return datetimet.strftime(str_format)
#     time_str = datetimet.astimezone(timezone.get_current_timezone())
#     return time_str.strftime(str_format)
# 
# def encodejson(status, body):
#     tmpjson={}
#     tmpjson['status'] = status
#     tmpjson['body'] = body
#     return simplejson.dumps(tmpjson)


# Path: app/blog_lab/views.py
import datetime
import ujson
from django.shortcuts import render_to_response
from django.http import HttpResponse
from django.utils import timezone
from dss.Serializer import serializer
from app.blog_lab.models import ProxyUser, Proxy
from app.blog_log.models import ReqRecord, BackLog
from app.utils import datetime_to_string, encodejson

# -*- coding: utf-8 -*-




# Create your views here.

def proxy(req):
    return render_to_response("proxy.html")


def monitor(req):
    return render_to_response("monitor.html")


def get_lab_info(req):
    body={}
    now = timezone.now()
    start = now - datetime.timedelta(hours=23, minutes=59, seconds=59)
    total_use = ProxyUser.objects.all().count()
    day_req = ReqRecord.objects.filter(uri='/lab/get_proxy/', create_time__gt=start).count()

    api_control = ReqRecord.objects.filter(create_time__gt=start).count()