コード例 #1
0
ファイル: views.py プロジェクト: panda7802/lxdzx_server_py3
def love_action(request, action):
    logging.debug(request.get_host() + " -- " + request.get_full_path())
    s = ""
    try:
        if action == "addzf":  # 增加祝福
            json_obj, session_res = t_url_tools.parse_url(request, is_check_session=False)
            name = json_obj['name']
            zf = json_obj['zf']
            ozf = ZF.objects.all().filter(name=name).first()
            if (None is ozf) or (name == ''):
                ozf = ZF()
                ozf.name = name
                ozf.zf = zf
                ozf.save()
            else:
                ozf.zf = zf
                ozf.save()
            s = t_url_tools.get_response_str({})
            return
        if action == "getZfByName":  # 通过姓名获取祝福
            json_obj, session_res = t_url_tools.parse_url(request, is_check_session=False)
            name = json_obj['name']
            zf = ZF.objects.all().filter(name=name).first()
            if None is zf:
                zfy = ""
            else:
                zfy = zf.zf
            s = t_url_tools.get_response_str({"zf": zfy})
            return
        if action == "getZfs":  # 获取所有祝福
            zfs = ZF.objects.all()
            res_zf = []
            for item in zfs:
                res_item = {}
                res_item['name'] = item.name
                res_item['zf'] = item.zf
                res_zf.append(res_item)
            s = t_url_tools.get_response_str(res_zf)
            return
        else:
            s = t_url_tools.get_response_str({}, success=False, msg="action不存在" + action)
            return
    except Exception as e:
        traceback.print_exc()
        logging.exception(e)
        s = t_url_tools.get_response_str({}, success=False, msg=action + " 异常",
                                         err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        s = s.encode('utf-16','surrogatepass').decode('utf-16')
        logging.debug(s)
        return HttpResponse(s)
コード例 #2
0
ファイル: xnjy.py プロジェクト: panda7802/lxdzx_server_py3
def xnjy_show(request):
    """
    新年寄语
    :param request:
    :return:
    """

    ui_type = 1
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        ui_type = int(json_obj['ui_type'])
    except Exception as e:
        pass

    if 1 == ui_type:
        ui_type = "yellow"
    else:
        ui_type = "blue"
    nick_name = ""
    try:
        nick_name = json_obj['nick_name']
    except Exception as e:
        pass

    xnjy = Xnjy.objects.filter(people_id__name=nick_name).first()
    if xnjy is None:
        print(xnjy)
        xnjy = Xnjy()
    # t = get_template('xnjy/input.html')
    # s = t.render({'xnjy': xnjy, 'ui_type': ui_type})

    t = get_template('xnjy/show.html')
    s = t.render({'xnjy': xnjy, 'ui_type': ui_type})
    return s
コード例 #3
0
def get_video_comment(request):
    s = "[]"
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        if not session_res:
            s = t_url_tools.get_session_err_res()
            return

        vid = json_obj['vid']
        parentid = json_obj['parentid']
        if int(parentid) > 0:
            vcs = Video_Comment.objects.filter(parent_comment_id_id=parentid).order_by("-is_top").order_by(
                "comment_time")
        else:
            vcs = Video_Comment.objects.filter(video_id_id=vid).order_by("-is_top").order_by("comment_time")

        response_data = []
        for item in vcs:
            res_item = {'comment': item.comment, 'id': item.id}
            response_data.append(res_item)
        s = t_url_tools.get_response_str(response_data)
    except Exception as e:
        traceback.print_exc()
        s = t_url_tools.get_response_str({}, success=False, msg="get_people_play_record 异常",
                                         err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #4
0
def add_video_comment(request):
    s = "[]"
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        if not session_res:
            s = t_url_tools.get_session_err_res()
            return

        vid = json_obj['vid']
        pid = json_obj['pid']
        comment = json_obj['comment']
        parentid = json_obj['parentid']

        video_comment = Video_Comment()
        video_comment.video_id = Video.objects.filter(id=vid).first()
        video_comment.people_id = People.objects.filter(id=pid).first()
        video_comment.comment = comment
        if int(parentid) > 0:
            video_comment.parent_comment_id_id = parentid
        video_comment.save()

        s = t_url_tools.get_response_str({})
    except Exception as e:
        traceback.print_exc()
        s = t_url_tools.get_response_str({}, success=False, msg="add_video_comment 异常",
                                         err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #5
0
def statistics_videos(request):
    """
    播放量
    :param request:
    :return:
    """
    s = "[]"
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        recs = Video_Record.objects.values_list('video_id').annotate(Count('video_id'))

        response_data = []
        for item in recs:
            video = Video.objects.filter(id=item[0]).first()
            count = item[1]
            video.play_count = count
            video.save()
            res_item = Video_Statistics_Model(video.title, count, video)  # {'video': video, "count": count}
            response_data.append(res_item)
        t = get_template('statistics.html')
        s = t.render({'res': response_data})
    except Exception as e:
        traceback.print_exc()
        s = t_url_tools.get_response_str({}, success=False, msg="statistics_videos 异常",
                                         err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #6
0
def get_ncov(request, action):
    """
    确诊人数
    :param request:
    :param action:
    :return:
    """
    logging.debug(request.get_full_path())

    # 无json
    try:
        if action == "get_pros":
            s = get_pros()
            return HttpResponse(s)
        elif action == "get_tj":
            s = get_tj()
            return HttpResponse(s)
    except Exception as e:
        logging.error(e)
        traceback.print_exc()
        s = t_url_tools.get_response_str(
            {},
            success=False,
            msg=action + "异常",
            err_code=t_url_tools.ERR_CODE_EXCEPTION)
        return HttpResponse(s)

    # 校验
    json_obj, session_res = t_url_tools.parse_url(request, False)
    s = ""

    try:
        if not session_res:
            s = t_url_tools.get_session_err_res()
        else:
            if action == "get_confirmed":
                s = get_confirmed(json_obj)
            elif action == "get_pro_his":
                s = get_pro_his(json_obj)
            elif action == "get_single_pro_his":
                s = get_single_pro_his(json_obj)
            else:
                s = t_url_tools.get_response_str(None,
                                                 msg=action + "不存在",
                                                 err_code=ERR_CODE_PARM,
                                                 success=False)
    except Exception as e:
        logging.error(e)
        traceback.print_exc()
        s = t_url_tools.get_response_str(
            {},
            success=False,
            msg=action + "异常",
            err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #7
0
ファイル: views.py プロジェクト: panda7802/lxdzx_server_py3
def get_web_data(request, action):
    """
    获取网络请求
    :param request:
    :param action:
    :return:
    """
    logging.debug(request.get_full_path())
    try:
        if action == "get_trt_ticket":
            s = get_trt_ticket()
    except Exception as e:
        logging.error(e)
        logging.error(traceback.format_exc())
        traceback.print_exc()
        s = t_url_tools.get_response_str(
            {},
            success=False,
            msg="--- " + action + "异常",
            err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)

    # 校验
    json_obj, session_res = t_url_tools.parse_url(request)
    s = ""

    try:
        if not session_res:
            s = t_url_tools.get_session_err_res()
        else:
            if action == "get_dgtj":
                s = get_dgtj(json_obj)
            elif action == "get_dgtj_echart":
                s = get_dgtj_echart(json_obj)
            elif action == "get_bili_video_tj_echart":
                s = get_bili_video_tj_echart(json_obj)
            else:
                s = t_url_tools.get_response_str(None,
                                                 msg=action + "不存在",
                                                 err_code=ERR_CODE_PARM,
                                                 success=False)
    except Exception as e:
        logging.error(e)
        traceback.print_exc()
        s = t_url_tools.get_response_str(
            {},
            success=False,
            msg=action + "异常",
            err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #8
0
def dzdp(request, action):
    """
       获取网络请求
       :param request:
       :param action:
       :return:
       """
    if action == "get_foods":
        json_obj = {'pid': 1}
        s = get_types_view(json_obj)
        return HttpResponse(s)

    # 校验
    json_obj, session_res = t_url_tools.parse_url(request)
    s = ""

    try:

        if not session_res:
            s = t_url_tools.get_session_err_res()
        else:
            logging.debug("------%s " % action)
            if action == "get_types":
                s = get_types(json_obj)
                logging.debug(s)
            elif action == "get_types_view":
                s = get_types_view(json_obj)
            elif action == "phb":
                s = get_phb(json_obj)
            elif action == "phb_view":
                s = get_phb_view(json_obj)
            else:
                s = t_url_tools.get_response_str(None,
                                                 msg=action + "不存在",
                                                 err_code=ERR_CODE_PARM,
                                                 success=False)
    except Exception as e:
        logging.error(e)
        traceback.print_exc()
        s = t_url_tools.get_response_str(
            {},
            success=False,
            msg=action + "异常",
            err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #9
0
def del_video_comment(request):
    s = "[]"
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        if not session_res:
            s = t_url_tools.get_session_err_res()
            return

        id = json_obj['id']

        video_comment = Video_Comment.objects.filter(id=id).first()
        video_comment.delete()
        s = t_url_tools.get_response_str({})
    except Exception as e:
        traceback.print_exc()
        s = t_url_tools.get_response_str({}, success=False, msg="add_video_comment 异常",
                                         err_code=t_url_tools.ERR_CODE_EXCEPTION)
    finally:
        return HttpResponse(s)
コード例 #10
0
ファイル: xnjy.py プロジェクト: panda7802/lxdzx_server_py3
def xnjy_index(request):
    """
    新年寄语
    :param request:
    :return:
    """
    ui_type = 1
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        ui_type = int(json_obj['ui_type'])
    except Exception as e:
        pass

    if 1 == ui_type:
        ui_type = "yellow"
    else:
        ui_type = "blue"

    t = get_template('xnjy/index.html')
    s = t.render({'ui_type': ui_type})
    return s
コード例 #11
0
ファイル: xnjy.py プロジェクト: panda7802/lxdzx_server_py3
def xnjy_gzh(request):
    ui_type = 0
    try:
        json_obj, session_res = t_url_tools.parse_url(request)
        ui_type = int(json_obj['ui_type'])
    except Exception as e:
        pass

    # url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxaa3e9bee4d1d172d&redirect_uri=https%3a%2f%2fwww.pandafly.cn%2flxdzx_show%2fxnjy_gzh&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
    # res = urllib2.urlopen(url).read()
    #   logging.debug("xnjy_gzh : " + res)

    # s = t.render({'xnjy': xnjy, 'ui_type': ui_type})
    #   s = "panguotian"
    code = request.GET.get('code')
    appid = "wxaa3e9bee4d1d172d"
    secret = "d0a7b8b491c15da6e3670da3d142495e"
    # 获取openid
    url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + code + "&grant_type=authorization_code"
    res = urllib2.urlopen(url).read()
    logging.debug(res)
    json_obj = JSONDecoder().decode(urllib.unquote(res))
    open_id = json_obj['openid']
    logging.debug("open_id : " + open_id)

    # 获取access_token
    # url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appid+"&secret="+secret+"&code="+code+"&grant_type=authorization_code"
    # res = urllib2.urlopen(url).read()
    # logging.debug(res)
    # json_obj = JSONDecoder().decode(urllib.unquote(res))
    access_token = json_obj[
        'access_token']  # twx_tools.getAccessToken(appid,secret)
    # 获取用户信息
    url = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + open_id + "&lang=zh_CN"
    res = urllib2.urlopen(url).read()
    logging.debug(res)
    s = res

    return s