Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
def play_video(json_obj):
    vid = json_obj['vid']
    pid = json_obj['pid']
    all_videos = Video.objects.filter(id=vid)
    if all_videos.__len__() <= 0:
        s = t_url_tools.get_response_str({}, success=False, msg="视频不存在", err_code=t_url_tools.ERR_CODE_DATA)
        return s

    all_peoples = People.objects.filter(id=pid)
    if all_peoples.__len__() <= 0:
        s = t_url_tools.get_response_str({}, success=False, msg="个人信息有误,请重新登录", err_code=t_url_tools.ERR_CODE_DATA)
        return s

    video_recod = Video_Record()
    video_recod.video_id = all_videos.first()
    video_recod.people_id = all_peoples.first()
    video_recod.save()

    # 记录播放量
    video_model = all_videos.first()
    play_count = video_model.play_count
    video_model.play_count = play_count + 1
    video_model.save()

    s = t_url_tools.get_response_str({})
    return s
Esempio n. 4
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)
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
def xnjy_save_xnjy(json_obj):
    # 增加微信名称
    nick_name = json_obj['nick_name']
    people = People.objects.filter(name=nick_name)
    #   people_count = people.__len__()
    people_count = 0
    if people_count <= 0:
        people = People()
        people.name = nick_name
        people.save()
        #       people = People.objects.filter(name=nick_name).first()
    else:
        people = people.first()

    xnjy = Xnjy.objects.filter(people_id=people).first()
    if xnjy is None:
        xnjy = Xnjy()
    xnjy.school = json_obj['school']
    xnjy.jy = json_obj['jy']
    xnjy.lx_time = json_obj['lx_time']
    xnjy.people_id = people
    xnjy.save()
    # res = {"id": people_id}
    s = t_url_tools.get_response_str({})
    return s
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
Esempio n. 11
0
def add_play_record(json_obj):
    vid = json_obj['vid']
    pid = json_obj['pid']

    video_rec = Video_Record()
    video_rec.video_id = Video.objects.filter(id=vid).first()
    video_rec.people_id = People.objects.filter(id=pid).first()
    video_rec.save()

    s = t_url_tools.get_response_str({})
    return s
Esempio n. 12
0
def login(json_obj):
    wx_name = json_obj['wx_name']
    people = People.objects.filter(wx_name=wx_name)
    people_count = people.__len__()
    if people_count > 0:
        people_id = people[0].id
    else:
        people = People()
        people.wx_name = wx_name
        people.save()
        people_id = people.id
    res = {"id": people_id}
    s = t_url_tools.get_response_str(res)
    return s
Esempio n. 13
0
def xnjy_get_xnjy(json_obj):
    # 增加微信名称
    nick_name = json_obj['nick_name']
    people = People.objects.filter(name=nick_name).first()
    res_item = {'school': ""}
    res_item['jy'] = ""
    res_item['lx_time'] = ""
    if people is not None:
        xnjy = Xnjy.objects.filter(people_id=people).first()
        if xnjy is not None:
            res_item = {'school': xnjy.school}
            res_item['jy'] = xnjy.jy
            res_item['lx_time'] = xnjy.lx_time
    # res = {"id": people_id}
    s = t_url_tools.get_response_str({'res': res_item})
    return s
Esempio n. 14
0
def get_people_fav(json_obj):
    pid = int(json_obj['pid'])
    vid = int(json_obj['vid'])

    if vid > 0:
        recs = People_Favorite.objects.filter(people_id_id=pid, video_id_id=vid).select_related('video_id')
    else:
        recs = People_Favorite.objects.filter(people_id_id=pid).select_related('video_id')

    response_data = []
    for item in recs:
        # print model_to_dict(item)
        # print item.video_id.title
        res_item = {'title': item.video_id.title}
        res_item['pic_url'] = t_url_tools.get_file_url(item.video_id.pic_url)[1]
        res_item['video_url'] = item.video_id.video_url
        res_item['desc'] = item.video_id.desc
        res_item['id'] = item.video_id.id
        response_data.append(res_item)
    s = t_url_tools.get_response_str(response_data)
    return s
Esempio n. 15
0
def do_my_fav(json_obj):
    """
    控制我的收藏
    :param request:
    :return:
    """
    vid = json_obj['vid']
    pid = json_obj['pid']

    s = ""
    pf = People_Favorite.objects.filter(video_id_id=vid).filter(people_id_id=pid).first()
    if pf is None:
        pf_new = People_Favorite()
        pf_new.video_id = Video.objects.filter(id=vid).first()
        pf_new.people_id = People.objects.filter(id=pid).first()
        pf_new.save()
        s = "添加收藏成功"
    else:
        pf.delete()
        s = "删除收藏成功"
    s = t_url_tools.get_response_str({'res': s})
    return s
Esempio n. 16
0
def get_people_play_record(json_obj):
    pid = json_obj['pid']
    people = People.objects.filter(id=pid).first()

    recs = Video_Record.objects.filter(people_id_id=pid).select_related('video_id').order_by("-watch_time")

    vids = []
    response_data = []
    for item in recs:
        if item.video_id.id in vids:
            continue
        else:
            vids.append(item.video_id.id)
        # print model_to_dict(item)
        # print item.video_id.title
        res_item = {'title': item.video_id.title}
        res_item['pic_url'] = t_url_tools.get_file_url(item.video_id.pic_url)[1]
        res_item['video_url'] = item.video_id.video_url
        res_item['desc'] = item.video_id.desc
        res_item['id'] = item.video_id.id
        res_item['watch_time'] = str(item.watch_time)[:str(item.watch_time).index(".")]
        response_data.append(res_item)
    s = t_url_tools.get_response_str(response_data)
    return s