Exemple #1
0
def user_list_bak():   # 第五课新增
    # form = None
    if request.method == "POST":
        pass
        # form = request.form  # 获取登录表单
    else:
        return layout('/pv/query.html', captions=[], rooms=[])

    names = [Room.accnt_name]
    user_lst = Room.query.with_entities(*names).filter().group_by(Room.accnt_name).order_by(Room.accnt_name).all()
    user_lst = [user[0] for user in user_lst]

    return layout('/pv/query.html', users=user_lst)
Exemple #2
0
def set_cookie():
    user_name = request.values.get("user_name")
    ck_content = request.values.get("ck_content")
    add_cookies(user_name=user_name, ck_content=ck_content)
    user_lst = Cookie.query.filter().all()
    accnt_names = [user.accnt_name for user in user_lst]
    return layout("/pv/query.html", accnt_names=accnt_names)
Exemple #3
0
def task_interface():
    if request.method == "POST":
        form = request.form
        try:
            if form:
                task = InterfaceTaskModel(
                    task_interface_name=form['task_interface_name'],
                    task_interface_method=form['task_interface_method'],
                    task_interface_url=form['task_interface_url'],
                    task_interface_params=form['task_interface_params'],
                    task_interface_trigger_type=form[
                        'task_interface_trigger_type'],
                    task_interface_trigger_arg=form[
                        'task_interface_trigger_arg'],
                    task_interface_trigger_value=form[
                        'task_interface_trigger_value'],
                    addtime=time.time(),
                    addwho=current_user.username,
                )
                db.session.add(task)
                db.session.commit()
                flash(u'添加成功', 'success')
                return redirect(url_for('admin.index'))
            else:
                flash(u'参数为空', 'error')
        except Exception as e:
            app.logger.error(e)
    return layout('task/interface.html')
Exemple #4
0
def user_list():  #第五课新增
    Role.insert_roles()
    username = session.get('username')
    role = session.get('role_id')
    user_list = User.query.outerjoin(Role, User.role_id == Role.id).all()
    return layout('/account/users.html',
                  users=user_list,
                  id=role,
                  user=username)
Exemple #5
0
def change_psswd():  # 第五课新增
    if request.method == 'POST':
        try:
            form = request.form
            use_info = User.query.filter(User.id == form['id']).first()
            use_info.password_hash = generate_password_hash(form['password'])
            db.session.commit()
            flash('修改密码成功!', 'success')
        except Exception as e:
            print(e)
            flash('修改密码失败!', 'error')
        return redirect(
            url_for(request.args.get('next') or 'account.user_list'))

    _id = request.values.get('id')
    user_info = User.query.filter_by(id=_id).first()
    return layout('/account/changepsswd.html', user_info=user_info)
Exemple #6
0
def user_edit():  #第五课新增
    if request.method == 'POST':
        try:
            form = request.form
            use_info = User.query.filter(User.id == form['id']).first()
            use_info.email = form['email']
            use_info.role_id = form['role_id']
            db.session.commit()
            flash('修改用户信息成功!', 'success')
        except Exception as e:
            print(e)
            flash('修改用户信息失败!', 'error')
        return redirect(
            url_for(request.args.get('next') or 'account.user_list'))

    id = request.values.get('id')
    user_info = User.query.filter_by(id=id).first()
    return layout('/account/edituser.html', user_info=user_info)
Exemple #7
0
def remotecmd():
    if request.method == "POST":
        form = request.form
        try:
            if form:
                task_remotecmd_host = form[
                    'task_remotecmd_hostandport'] if not ':' in form[
                        'task_remotecmd_hostandport'] else form[
                            'task_remotecmd_hostandport'].split(':')[0]
                task_remotecmd_port = '22' if not ':' in form['task_remotecmd_hostandport'] else \
                    form['task_remotecmd_hostandport'].split(':')[1]
                task = RemotecmdTaskModel(
                    task_remotecmd_name=form['task_remotecmd_name'],
                    task_remotecmd_host=task_remotecmd_host,
                    task_remotecmd_port=task_remotecmd_port,
                    task_remotecmd_username=form['task_remotecmd_username'],
                    task_remotecmd_password=form['task_remotecmd_password'],
                    task_remotecmd_trigger_type=form[
                        'task_remotecmd_trigger_type'],
                    task_remotecmd_trigger_arg=form[
                        'task_remotecmd_trigger_arg'],
                    task_remotecmd_trigger_value=form[
                        'task_remotecmd_trigger_value'],
                    task_remotecmd_cmd_type=form['task_remotecmd_cmd_type'],
                    task_remotecmd_cmd_value=form['task_remotecmd_cmd_value'],
                    addtime=time.time(),
                    addwho=current_user.username,
                )
                db.session.add(task)
                db.session.commit()
                flash(u'添加成功', 'success')
                return redirect(url_for('admin.index'))
            else:
                flash(u'参数为空', 'error')
        except Exception as e:
            app.logger.error(e)

    return layout('task/remotecmd.html')
Exemple #8
0
def user_edit():   # 第五课新增
    if request.method == 'POST':
        try:
            form = request.form
            org_name = form['org_name']
            new_name = form["new_name"]
            org_cookie = Cookie.query.filter_by(accnt_name=org_name).first()
            new_cookie = Cookie(accnt_name=new_name, ck_content=org_cookie.ck_content)
            db.session.add(new_cookie)
            rooms = Room.query.filter_by(accnt_name=org_name).all()
            for room in rooms:
                room.accnt_name = new_name
            db.session.delete(org_cookie)
            db.session.commit()
            flash('修改直播账户信息成功!', 'success')
        except Exception as e:
            print(e)
            flash('修改直播账户信息失败!', 'error')
        return redirect(url_for(request.args.get('next') or 'live.user_list'))

    accnt = request.values.get('accnt')
    user_info = Cookie.query.filter_by(accnt_name=accnt).first()
    return layout('/live/edituser.html', user_info=user_info)
Exemple #9
0
def index():
    return layout('/base/index.html')
Exemple #10
0
def room_list():   # 第五课新增
    # form = None
    if request.method == "POST":
        form = request.form  # 获取登录表单
    else:
        user_lst = Cookie.query.filter().all()
        accnt_names = [user.accnt_name for user in user_lst]
        return layout('/pv/query.html', captions=[], rooms=[], accnt_names=accnt_names)

    dct = {
        "room_id": [Room.room_id, "直播间ID"],
        "start_time": [Room.start_time, "开始时间"],
        "ttl_per_nm": [Room.ttl_per_nm, "进入直播间总人数"],
        "max_oln_nm": [Room.max_oln_nm, "最大在线人数"],
        "avg_oln_nm": [Room.avg_oln_nm, "平均在线人数"],
        "prd_cmt_nm": [Room.prd_cmt_nm, "评论数"],
        "prd_lik_nm": [Room.prd_lik_nm, "点赞数"],
        "inc_fan_nm": [Room.inc_fan_nm, "新增粉丝数"],
        "fan_per_rt": [Room.fan_per_rt, "进粉率"],
        "avg_wth_tm": [Room.avg_wth_tm, "人均观看时长"],
        "prd_shw_nm": [Room.prd_shw_nm, "商品曝光人数"],
        "prd_clk_nm": [Room.prd_clk_nm, "商品点击人数"],
        "pay_per_nm": [Room.pay_per_nm, "成交人数"],
        "prd_oln_nm": [Room.prd_oln_nm, "上架商品数"],
        "pay_ord_nm": [Room.pay_ord_nm, "成交订单量"],
        "prd_shw_rt": [Room.prd_shw_rt, "商品点击率"],
        "pay_per_rt": [Room.pay_per_rt, "曝光转化率"],
        "pay_prd_nm": [Room.pay_prd_nm, "成交商品数"],
        "pay_moneys": [Room.pay_moneys, "成交金额"],
        "person_val": [Room.person_val, "人均价值"],
        "ord_per_rt": [Room.ord_per_rt, "订单创建率"],
        "ord_pay_rt": [Room.ord_pay_rt, "创建成交率"],

        "nat_cmd_fd": [Room.nat_cmd_fd, "自然推荐-推荐feed流量比率"],
        "nat_fcs_tb": [Room.nat_fcs_tb, "关注tab流量比率"],
        "nat_search": [Room.nat_search, "搜索流量比率"],
        "nat_living": [Room.nat_living, "自然推荐-直播广场流量比率"],
        "nat_sam_ct": [Room.nat_sam_ct, "自然推荐-同城feed流量比率"],
        "nat_others": [Room.nat_others, "其他流量比率"],
        "nat_per_hm": [Room.nat_per_hm, "个人主页流量比率"],
        "nat_sht_fl": [Room.nat_sht_fl, "短视频引流流量比率"],
        "nat_cmd_ot": [Room.nat_cmd_ot, "自然推荐-其他流量比率"],
        "nat_dy_mal": [Room.nat_dy_mal, "抖音商城流量比率"],

        "pay_sm_cmd": [Room.pay_sm_cmd, "小店随心推流量比率"],
        "pay_ths_pc": [Room.pay_ths_pc, "千川PC版流量比率"],
        "pay_dou_ad": [Room.pay_dou_ad, "DOU+广告流量比率"],
        "pay_oth_ad": [Room.pay_oth_ad, "其他竞价广告流量比率"],
        "pay_top_lv": [Room.pay_top_lv, "品牌广告-toplive流量比率"],
        "pay_top_ot": [Room.pay_top_ot, "品牌广告-其他流量比率"],
    }
    s_option = request.values.getlist("s_option")
    captions = ["用户名"]
    names = [Room.accnt_name]
    room_lst = []
    start_time = request.values.get("start_time")
    end_time = request.values.get("end_time")

    user_lst = Room.query.with_entities(Room.accnt_name).group_by(Room.accnt_name).order_by(Room.accnt_name).all()
    user_lst = [user[0] for user in user_lst]
    # pdb.set_trace()
    if "query" in form:
        names.append(Room.start_time)
        captions.append("直播时间")
        for s in s_option:
            names.append(dct[s][0])
            captions.append(dct[s][1])

        # pdb.set_trace()
        room_lst = Room.query.with_entities(*names).filter(Room.start_time >= start_time). \
            filter(Room.start_time <= end_time).order_by(Room.start_time).all()
        sz = len(captions)
        for i in range(2, sz):
            # caption = captions[i]
            data = []
            for room in room_lst:
                data.append({"x": room[1], "y": room[i]})

    elif "compare" in form:
        for s in s_option:
            if s == "room_id":
                continue
            names.append(func.avg(dct[s][0]))
            captions.append(dct[s][1])
        room_lst = Room.query.with_entities(*names).filter(Room.start_time >= start_time). \
            filter(Room.start_time <= end_time).group_by(Room.accnt_name).all()

    sz = len(room_lst)
    rooms = []
    for i in range(sz):
        rooms.append([it for it in room_lst[i]])
        for j, cap in enumerate(captions):
            if "率" in cap:
                val = 0
                if room_lst[i][j] is not None:
                    val = float(100*room_lst[i][j])
                rooms[i][j] = "%.2f%%" % val
            elif cap == "直播间ID" or cap == "开始时间":
                continue
            else:
                val = room_lst[i][j]
                tmp = ""
                if type(val) is not int and type(val) is not float:
                    continue
                if type(val) is float:
                    val1 = math.floor(val)
                    val2 = val - val1
                    tmp = ("%.2f" % val2)[1:]
                    val = val1
                while val >= 1000:
                    tmp = ",%03d" % (val % 1000) + tmp
                    val //= 1000
                tmp = "%d" % val + tmp
                rooms[i][j] = tmp

    return layout('/pv/query.html', captions=captions, rooms=rooms, users=user_lst)
Exemple #11
0
def room_detail():   # 第五课新增
    # pdb.set_trace()
    room_id = request.values.get('id')
    details = Room.query.filter(Room.id == room_id).all()
    return layout('/pv/detail.html', infos=details)
Exemple #12
0
def query_user():   # 第五课新增
    # form = None
    if request.method == "POST":
        form = request.form  # 获取登录表单
    else:
        return layout('/pv/query.html')

    download_names = []
    # pdb.set_trace()
    if "data_download" in form:
        for item in request.values:
            # pdb.set_trace()
            if form[item] == "on":
                download_names.append(item)
        for accnt_name in download_names:
            print(accnt_name)
            cookie = Cookie.query.filter(Cookie.accnt_name == accnt_name).first()
            if cookie is None:
                continue
                # return -1
            else:
                ck_content = cookie.ck_content
                # rooms = Room.query.with_entities(Room.room_id).filter(Room.accnt_name == accnt_name).all()
                rooms = Room.query.filter(Room.accnt_name == accnt_name).all()
                room_ids = set([room.room_id for room in rooms])

                # get flow info
                flows = {room.room_id: room.nat_cmd_fd for room in rooms}

                res_code = _get_room_info(ck_content=ck_content, done_room_ids=room_ids, accnt_name=accnt_name, flows=flows)
                if res_code == 200:
                    flash("账户 %s 数据下载成功!" % accnt_name, 'success')
                else:
                    flash("账户 %s 数据下载失败!请重新设置cookie" % accnt_name, 'error')
                    break

    elif "accnt_delete" in form:
        delete_names = []
        for item in request.values:
            # pdb.set_trace()
            if form[item] == "on":
                delete_names.append(item)
        try:
            for accnt_name in delete_names:
                rooms = Room.query.filter(Room.accnt_name == accnt_name).all()
                for room in rooms:
                    db.session.delete(room)
                    db.session.commit()
                flash("账户 %s 数据删除成功!" % accnt_name, 'success')
                user = Cookie.query.filter(Cookie.accnt_name == accnt_name).first()
                db.session.delete(user)
                db.session.commit()
                flash('账户 %s 删除成功!' % accnt_name, 'success')
        except Exception as e:
            print(e)
            flash('账户删除失败!', 'error')

    user_lst = Cookie.query.filter().all()
    accnt_names = [user.accnt_name for user in user_lst]
    # return redirect(url_for(request.args.get('next') or 'account.user_list'))

    return layout('/pv/query.html', accnt_names=accnt_names)
Exemple #13
0
def user_list():  # 第五课新增
    _user_list = User.query.outerjoin(Role, User.role_id == Role.id).all()
    return layout('/account/users.html', users=_user_list)
Exemple #14
0
def user_list():  # 第五课新增
    user_lst = Cookie.query.filter().all()
    accnt_names = [user.accnt_name for user in user_lst]
    return layout('/live/users.html', accnt_names=accnt_names)