def get_ip(req):
    body={}
    token = req.POST.get('private_token', None)
    reset = req.POST.get('reset', False)
    if token is None:
        body['msg'] = 'missing required parameter: private_token'
        return HttpResponse(encodejson(7, body), content_type="application/json")
    p_user_list = ProxyUser.objects.filter(token=token)
    if not p_user_list.exists():
        body['msg'] = 'invalid private_token'
        return HttpResponse(encodejson(6, body), content_type="application/json")
    user = p_user_list[0]
    ip_list = Proxy.objects.all()
    ip_count = ip_list.count()
    req_list = []
    reqed = user.record.split(',')
    for i in range(0, 5):
        r_num = random.randint(1, ip_count)
        proxy = ip_list[(r_num - 1)]
        if str(proxy.id) in reqed:
            r_num = random.randint(1, ip_count)
            proxy = ip_list[(r_num - 1)]
        ip_body={}
        ip_body['ip'] = proxy.ip
        ip_body['id'] = proxy.id
        ip_body['create_time'] = datetime_to_string(proxy.create_time)
        ip_body['modify_time'] = datetime_to_string(proxy.modify_time)
        req_list.append(copy.copy(ip_body))
        if str(proxy.id) not in reqed:
            user.record = user.record + str(proxy.id) + ','
    user.save()
    body['proxy_list'] = req_list
    return HttpResponse(encodejson(1, body), content_type="application/json")
示例#2
0
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()
    proxy_count = Proxy.objects.all().count()
    back_log = BackLog.objects.all()
    if back_log.exists():
        back_log = back_log.order_by('-create_time')
        new_time = datetime_to_string(back_log[0].create_time)
    else:
        new_time = '未更新'
    body['api_control'] = api_control
    body['api_status'] = True
    body['total_user'] = total_use
    body['req_times'] = day_req
    body['proxy_num'] = proxy_count
    body['update_time'] = new_time
    return HttpResponse(encodejson(1, body), content_type="application/json")
示例#3
0
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()
    proxy_count = Proxy.objects.all().count()
    back_log = BackLog.objects.all()
    if back_log.exists():
        back_log = back_log.order_by('-create_time')
        new_time = datetime_to_string(back_log[0].create_time)
    else:
        new_time = '未更新'
    body['api_control'] = api_control
    body['api_status'] = True
    body['total_user'] = total_use
    body['req_times'] = day_req
    body['proxy_num'] = proxy_count
    body['update_time'] = new_time
    return HttpResponse(encodejson(1, body), content_type="application/json")