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'}
def send_manual(project,noti): import platform # print(noti) v = send(data=noti,project=project) send_result = v.play_all() timenow=int(time.time()) if send_result : if 'success' in send_result or 'ok' in send_result: update_noti(project=project,noti_id=noti[0],updated_at=timenow,status=26,recall_result=send_result) update_noti_group(project=project,noti_group_id=noti[1],sent=1) else: update_noti(project=project,noti_id=noti[0],updated_at=timenow,status=27,recall_result=send_result) content = json.loads(noti[3]) if "send_tracker" in content: send_tracker = content["send_tracker"] else : send_tracker = {"properties":{}} remark = None if "ghost_sa" in content and "remark" in content["ghost_sa"]: remark = content["ghost_sa"]["remark"] send_tracker['properties']['sent_result'] = send_result # print(send_tracker) insert_event(table=project,alljson=json.dumps(send_tracker),track_id=0,distinct_id=noti[4],lib='noti',event='recall',type_1='track',User_Agent='',Host='',Connection='',Pragma='',Cache_Control='',Accept='',Accept_Encoding='',Accept_Language='',ip='',ip_city='{}',ip_asn='{}',url='',referrer='',remark=remark,ua_platform=platform.system(),ua_browser='',ua_version='',ua_language='') return noti[0],send_result return 'no_result'
def create_non_usergroup_non_temple_noti(args): #手动创建不在用户分群,也不适用模板的消息 start_time = int(time.time()) if 'data' in args and args[ 'data'] and args['data'] != '' and 'project' in args and args[ 'project'] != '' and 'medium_id' in args: 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 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=None, owner=owner, send_at=send_at, sent=0, total=len(args['data']), priority=13, status=status) inserted = 0 for item in args['data']: insert_result = insert_noti( project=args['project'], type_1=args['medium_id'], created_at=int(time.time()), updated_at=int(time.time()), distinct_id=item['distinct_id'], content=item, send_at=item['send_at'] if 'send_at' in item else send_at, plan_id=None, list_id=None, data_id=None, temple_id=None, noti_group_id=result_group[2], priority=13, status=status, owner=owner, recall_result=None, key=item['key'] if 'key' in item else None, level=item['level'] if 'level' in item else None) inserted = inserted + insert_result[1] 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'}
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'