def delete_group(): response = {'response': 'error'} group_id = request.args.get('id') group = QueryPg(table='groups', data={'id': group_id}).delete() if group > 0: message_box = QueryMongo(collection_type='message_box_g' + group_id, query_type=0).delete() task_board = QueryMongo(collection_type='task_board_g' + group_id, query_type=0).delete() if message_box and task_board: response['response'] = 'success' return json.dumps(response)
def new_contact_user(): response = {'response': 'error'} initiator_id = request.args.get('user_id') invite_id = request.args.get('friend_id') name_box = 'message_box_u'+initiator_id+"_u"+invite_id if len(QueryPg(table='user_contacts', data={'message_box': name_box}).select()) == 0: id_message = QueryMongo(collection_type=name_box, data={mongo_collections['message_box']}).insert() QueryMongo(collection_type=name_box, data={"_id": ObjectId(id_message)}).delete() QueryPg(table='user_contacts_'+initiator_id, data={'user_id': initiator_id, 'friend_id': invite_id, 'message_box': name_box}).insert() QueryPg(table='user_contacts_'+invite_id, data={'user_id': invite_id, 'friend_id': initiator_id, 'message_box': name_box}).insert() response['response'] = 'success' return json.dumps(response)
def delete_user(): response = {'response': 'error'} user = QueryPg(data={'id': request.args.get('id')}).delete() if user > 0: QueryMongo(collection_type='task_board_u', name_collection=request.args.get('id'), query_type=0).delete() response['response'] = 'success' return json.dumps(response)
def complete_task(): response = {'response': 'error'} if QueryMongo(collection_type=request.args.get('table_name'), data={'_id': ObjectId(request.args.get('id'))}, update_data={'$set': {'completed': request.args.get('result')}}).update(): response['response'] = 'success' return json.dumps(response)
def create_task(rule): response = {'response': 'Pleas enter correct URL'} if rule == 'auto': date_appearence, content = task_analization.main(request.args.get('content')) elif rule == 'manually': date_appearence = request.args.get('date_executions') content = request.args.get('content') else: return json.dumps(response) for item in QueryPg(table='users', column='role_id', data={'id': request.args.get('author')}).select(): for iter in QueryPg(table='role', column='cost', data={'id': item}).select(): if QueryMongo(collection_type=request.args.get('table_name'), data={ 'date_appearance': datetime.now(), 'date_executions': date_appearence, 'cost': iter, 'completed': False, 'content_task': [{ 'type': request.args.get('type'), 'content': content }]}).insert(): response['response'] = 'success' return json.dumps(response)
def rewrite_message(): response = {'response': 'error'} if QueryMongo(name_collection=request.args.get('table_name'), data={'_id': ObjectId(request.args.get('id'))}, update_data={'$set': {'message_content': [ {'content': request.args.get('new_content')}]}}).update(): response['response'] = 'success' return json.dumps(response)
def contacts_user(query_class): message_box = {} contact_list = {} for item in query_class.select(): message_box['contact'] = item['friend_id'] message_box[item['message_box']] = QueryMongo(collection_type=item['message_box'], query_type=0) message_box[item['message_box']].select() contact_list[item['message_box']] = {message_box} message_box.clear() return message_box
def delete_contact_user(): response = {'response': 'error'} initiator_id = request.args.get('user_id') invite_id = request.args.get('friend_id') name_box = QueryPg(table='user_contacts', child_name='_' + initiator_id, data={'friend_id': invite_id}).select() for item in name_box: if QueryPg(table='user_contacts', data={'message_box': item['message_box']}).delete() == 2: QueryMongo(collection_type=str(item['message_box']), query_type=0).delete() response['response'] = 'success' return json.dumps(response)
def show_message(): response = {'response': 'error'} messages = '' for item in QueryMongo(collection_type=request.args.get('table_name'), query_type=0).select(): messages += str(item) if messages: response['response'] = 'success' response['messages'] = messages return json.dumps(response)
def sentimental_analysis_group(): response = {'response': 'error'} list_massage = [] for item in QueryMongo(collection_type='message_box_g', name_collection=request.args.get('id')).select(): if item['content_message']['type'] == 'text': list_massage.append(item['content_message']['content']) if list_massage: response['response'] = 'success' response['result'] = sentimental.main(list_massage) return json.dumps(response)
def send_message(): response = {'response': 'error'} message = QueryMongo(collection_type=request.args.get('table_name'), data={'from_id': request.args.get('from_id'), 'to_id': request.args.get('to_id'), 'datetime': datetime.datetime.now(), 'content_message': [ {'type': request.args.get('type'), 'content': request.args.get('content')}]}).insert() print(message) if message: response['response'] = 'success' return json.dumps(response)
def create_user(): response = {'response': 'error'} data = {} cr_dict = pg_tables['users'] if cr_dict.get('id') != None : cr_dict.pop('id') if cr_dict.get('contacts_list') != None: cr_dict.pop('contacts_list') if cr_dict.get('tasks_board') != None: cr_dict.pop('tasks_board') for key in cr_dict: if key == 'role_sys_id' or key == 'role_company_id': data[key] = int(request.args.get(key)) elif key == "date_born": data[key] = datetime.datetime.strptime(request.args.get(key), "%Y-%m-%d") else: data[key] = request.args.get(key) user_id = QueryPg(data=data).insert() task_board = QueryMongo(collection_type="task_board_u" + user_id, data={mongo_collections['task_board']}).insert() if task_board: print(task_board) QueryMongo(collection_type="task_board_u", name_collection=user_id, data={'_id': ObjectId(task_board)}).delete() response['response'] = 'succsess' return json.dumps(response)
def new_group(): response = {'response': 'error'} data = {} cr_dict = pg_tables['groups'] if cr_dict.get('id') !=None : cr_dict.pop('id') if cr_dict.get('group_contact') !=None : cr_dict.pop('group_contact') if cr_dict.get('group_message_box') !=None : cr_dict.pop('group_message_box') for key in cr_dict: data[key] = request.args.get(key) group_id = QueryPg(table='groups', data=data).insert() message_box = QueryMongo(collection_type='message_box_g'+group_id, data={mongo_collections['message_box']}).insert() task_board = QueryMongo(collection_type='task_board_g' + group_id, data={mongo_collections['task_board']}).insert() if message_box and task_board: QueryMongo(collection_type='message_box_g' + group_id, data={'_id': ObjectId(message_box)}).delete() QueryMongo(collection_type='task_board_g' + group_id, data={'_id': ObjectId(task_board)}).delete() response['response'] = 'success' return json.dumps(response)
def check_success_task(): response = {'response': 'Pleas enter correct URL'} in_progress = 0 failed = 0 done = 0 all_task = 0 for item in QueryMongo(collection_type=request.args.get('table_name')).select(): if request.args.get('start') <= item['date_execution'] <= request.args.get('finish') \ or request.args.get('start') <= item['date_appearance'] <= request.args.get('finish'): all_task += item['cost'] if item['completed'] == 'in_progress': in_progress += item['cost'] if item['completed'] == 'failed': failed += item['cost'] if item['completed'] == 'done': done += item['cost'] response['in_progress'] = {'percent': percent(all_task, in_progress), 'cost': in_progress} response['failed'] = {'percent': percent(all_task, failed), 'cost': failed} response['done '] = {'percent': percent(all_task, done), 'cost': done} response['all_task']['cost'] = all_task response['response'] = 'success' return json.dumps(response)
def delete_task(): response = {'response': 'error'} if QueryMongo(collection_type=request.args.get('table_name'), data={'_id': ObjectId(request.args.get('id'))}).delete(): response['response'] = 'success' return json.dumps(response)