Exemple #1
0
def show_temple_args():
    #查询模板需要的参数
    project = get_url_params('project')
    password = get_url_params('password')
    owner = get_url_params('owner')
    temple_id = get_url_params('temple_id')
    if password == admin.admin_password and request.method == 'POST' and owner and owner != '' and project:
        result_temple = select_noti_temple(project=project,
                                           temple_id=temple_id)
        args = json.loads(result_temple[0][0][2])
        contents = json.loads(result_temple[0][0][3])
        if result_temple[1] > 0:
            args_pending = ['distinct_id']
            import re
            args_content = re.findall(r'___(\w+)___', result_temple[0][0][2])
            for item in args_content:
                if item not in args_pending:
                    args_pending.append(item)
            returnjson = {
                'result': 'success',
                'args': args,
                'content': contents,
                'need': args_pending
            }
            return jsonify(returnjson)
        else:
            returnjson = {'result': 'fail', 'error': '该模板不存在'}
            return jsonify(returnjson)
    else:
        returnjson = {'result': 'fail', 'error': '参数错误'}
        return jsonify(returnjson)
Exemple #2
0
def create_non_usergroup_noti(args):
    #手动创建不在用户分群里的消息
    start_time = int(time.time())
    if 'data' in args and args['data'] and args['data'] !='' and 'project' in args and args['project'] !='':
        owner = args['owner'] if 'owner' in args else 'undefined'
        status = int(args['status']) if 'status' in args and args['status'] is not None else 9
        if 'temple_id' in args and args['temple_id'] != '':
            result_temple = select_noti_temple(project=args['project'],temple_id=args['temple_id'])
        if 'result_temple' in dir():
            medium_id = json.loads(result_temple[0][0][2])['meta']['medium_id']
        elif 'medium_id' in args:
            medium_id = args['medium_id']
        send_at = args['send_at'] if 'send_at' in args else int(time.time())
        result_group = insert_noti_group(project=args['project'],plan_id=None,list_id=None,data_id=None,temple_id=args['temple_id'] if 'temple_id' in args else None,owner=owner,send_at=send_at,sent=0,total=len(args['data']),priority=13,status=status)
        inserted = 0
        for noti in args['data']:
            if 'send_tracker' in noti and 'distinct_id' in noti['send_tracker'] and noti['send_tracker']['distinct_id'] != '':
                insert_result = insert_noti(project=args['project'],type_1=medium_id,created_at=int(time.time()),updated_at=int(time.time()),distinct_id=noti['send_tracker']['distinct_id'],content=noti,send_at=noti['send_at'] if 'send_at' in noti else send_at,plan_id=None,list_id=None,data_id=None,temple_id=result_temple[0][0][0],noti_group_id=result_group[2],priority=13,status=status,owner=owner,recall_result=None,key=noti['key'] if 'key' in noti else None,level=noti['level'] if 'level' in noti else None)
                inserted = inserted+insert_result[1]
        if 'temple_id' in args and args['temple_id'] != '':
            update_noti_temple(project=args['project'],temple_id=args['temple_id'],apply_times=1,lastest_apply_time=int(time.time()),lastest_apply_list = 0)
        update_noti_group(project=args['project'],noti_group_id=result_group[2])
        return {'result':'success','inserted':inserted,'timecost':int(time.time())-start_time}
    else:
        return {'result':'failed','error':'no_distinct_id_or_miss_data'}
Exemple #3
0
def create_auto_group():
    projects_result, project_count = select_scheduler_enable_project()
    write_to_log(filename='scheduler',
                 defname='create_auto_group',
                 result='获取项目列表' +
                 (str(project_count) if project_count else '0'))
    for project in projects_result:
        result_auto_noti = select_auto_temple_apply_plan(project=project[0])
        # print(result_auto_noti)
        for data_list in result_auto_noti[0]:
            # print(data_list)
            func_data = json.loads(data_list[2])
            # print(func_data)
            id_list = []
            if "default_temple" in func_data and type(
                    func_data["default_temple"]) is list:
                for temple_id in func_data["default_temple"]:
                    id_list.append(temple_id)
            elif "default_temple" in func_data and type(
                    func_data["default_temple"]) is int:
                id_list.append(func_data["default_temple"])
            for tid in id_list:
                send_at = []
                result_temple = select_noti_temple(project=project[0],
                                                   temple_id=tid)
                if result_temple[1] > 0 and result_temple[0][0][2]:
                    args = json.loads(result_temple[0][0][2])
                    if 'meta' in args and 'default_send_time' in args['meta']:
                        print(args['meta']['default_send_time'])
                        send_at_list = get_next_time(
                            timer=args['meta']['default_send_time'],
                            current_time=int(time.time()))
                        # org_data_time_list = get_next_time(timer = args['meta']['default_send_time'],current_time=data_list[3])
                        # if send_at_list == send_at_list :
                        for time_return in send_at_list:
                            send_at.append(time_return['time_int'])
                    elif len(send_at) == 0:
                        send_at.append(int(time.time()))
                    for send_int in send_at:
                        create_noti_group(project=project[0],
                                          temple_id=tid,
                                          user_group_id=data_list[1],
                                          data_id=None,
                                          owner='create_auto_group',
                                          send_at=send_int)
Exemple #4
0
def create_manual_temple_noti():
    #外部触发模板消息
    project = get_url_params('project')
    temple_id = get_url_params('temple_id')
    send_at = get_url_params('send_at') if get_url_params('send_at') else int(
        time.time())
    password = get_url_params('password')
    owner = get_url_params('owner')
    data = get_url_params('data')
    if password == admin.admin_password and request.method == 'POST' and owner and owner != '' and project:
        try:
            data_jsons = json.loads(data)
            data_list = []
            for item in data_jsons:
                print(item)
                if 'distinct_id' in item and 'data_json' in item:
                    result_temple = select_noti_temple(project=project,
                                                       temple_id=temple_id)
                    result = apply_temple(
                        project=project,
                        temple_args=json.loads(result_temple[0][0][2]),
                        temple_content=json.loads(result_temple[0][0][3]),
                        data_json=item['data_json'],
                        data_key=item['distinct_id'],
                        send_at=send_at,
                        group_id=None,
                        owner=owner)
                    data_list.append(result)
            result_insert = create_non_usergroup_noti(
                args={
                    'owner': owner,
                    'temple_id': temple_id,
                    'project': project,
                    'data': data_list
                })
            return jsonify(result_insert)
        except Exception:
            error = traceback.format_exc()
            write_to_log(filename='api_noti',
                         defname='create_manual_temple_noti',
                         result=error)
            returnjson = {'result': 'fail', 'error': error}
            return jsonify(returnjson)
Exemple #5
0
def create_noti_group(project,
                      temple_id,
                      user_group_id=None,
                      data_id=None,
                      owner='noti',
                      send_at=None):
    #对分群应用模板,有data_id时,优先使用data_id
    result_temple = select_noti_temple(project=project, temple_id=temple_id)
    if not user_group_id and not data_id:
        return 'no_group'
    else:
        if user_group_id and not data_id:
            result_data = select_usergroup_data(project=project,
                                                group_list_id=user_group_id)
        elif data_id:
            result_data = select_usergroupdata_data(project=project,
                                                    data_id=data_id)
        timenow = int(time.time())
        result_group = insert_noti_group(
            project=project,
            plan_id=result_data[0][0][0],
            list_id=result_data[0][0][1],
            data_id=result_data[0][0][2],
            temple_id=result_temple[0][0][0],
            owner=owner,
            send_at=send_at if send_at else timenow,
            sent=0,
            total=result_data[1],
            priority=13,
            status=result_data[0][0][6])
        for noti in result_data[0]:
            timenow = int(time.time())
            temple_content = apply_temple(
                project=project,
                temple_args=json.loads(result_temple[0][0][2]),
                temple_content=json.loads(result_temple[0][0][3]),
                data_json=json.loads(noti[5]),
                data_key=noti[4],
                group_id=user_group_id,
                owner=owner,
                send_at=send_at if send_at else timenow)
            insert_result = insert_noti(
                project=project,
                type_1=json.loads(result_temple[0][0][2])['meta']['medium_id'],
                created_at=timenow,
                updated_at=timenow,
                distinct_id=noti[4],
                content=temple_content,
                send_at=send_at if send_at else timenow,
                plan_id=noti[0],
                list_id=noti[1],
                data_id=noti[2],
                temple_id=result_temple[0][0][0],
                noti_group_id=result_group[2],
                priority=13,
                status=noti[6],
                owner=owner,
                recall_result=None,
                key=temple_content['key'] if 'key' in temple_content else None,
                level=temple_content['level']
                if 'level' in temple_content else None)
        update_noti_temple(
            project=project,
            temple_id=temple_id,
            apply_times=1,
            lastest_apply_time=timenow,
            lastest_apply_list=user_group_id if user_group_id else 0)
        update_noti_group(project=project, noti_group_id=result_group[2])
        update_usergroup_list(project=project,
                              list_id=result_data[0][0][1],
                              apply_temple_times=1)
        update_usergroup_plan(project=project,
                              plan_id=result_data[0][0][0],
                              latest_apply_temple_id=temple_id,
                              latest_apply_temple_time=timenow)
        return 'success'