def profile(): profileName = request.form.get('nickName') modeProfile = 'espect' response = user.select().where(user.nickName == profileName).execute() if len(response) > 0: if isBaned(response[0].id): return { 'error': { 'type': 'ban-profile', 'messege': 'Esta cuenta a sido suspendida' } } return { 'profile': { 'id': response[0].id, 'name': response[0].userName, 'lastName': response[0].lastName, 'mode': modeProfile, 'videos': [], 'moments': [], 'followers': 0, 'description': response[0].description, 'email': response[0].email, 'videos': [] } } return {'error': {'type': '', 'messege': 'Profile not exit'}}
def search(): query=request.form.get('query') queryArray = query.split(' ') usersProfileList = [] for itemQueryArray in queryArray: response = user.select().where(user.nickName == itemQueryArray).execute() if len(response) > 0: if isBaned(response[0].id) is not True: usersProfileList.append({ 'profile':{ 'nickName':response[0].nickName, 'userName':response[0].userName, 'lastName':response[0].lastName, 'id':response[0].id, 'followers':'' } }) return { 'responseSize':len(usersProfileList), 'profiles':usersProfileList }
def getVideo(postId): query = post.select().where(post.id == postId).execute() if len(query) > 0: if isBaned(query[0].idPosteador) is not True: return { 'post': { 'postId': query[0].id, 'postMode': query[0].videoMode, 'likes': 0, 'messege': query[0].messege, 'date': query[0].datePost, 'videoUrl': 'http://localhost:5000/video/{}/'.format(query[0].id), 'reproductions': 0, 'comments': [], 'hashtags': query[0].hashtags.split(' '), 'posteador': {} } } return { 'error': { 'type': 'poster-ban', 'messege': 'La cuenta del posteador a sido suspendida' } } return { 'error': { 'type': 'video-not-found', 'messege': 'Video no encontrado' } }, 404
def login(): email = request.form.get('email') password = request.form.get('password') if request.method == 'POST': if compruebateEmail(email): session = user.select().where((user.email == email).bin_and( user.password == password)).execute() if len(session) is not 0: if isBaned(session[0].id): return { 'error': { 'type': 'ban-account', 'messege': 'Tu cuenta a sido suspendida' } } return jsonify({ 'session': { 'id': session[0].id, 'userName': session[0].userName, 'lastName': session[0].lastName, 'nickName': session[0].nickName, 'email': session[0].email, 'sexo': session[0].sexo, 'sessioKey': '', 'profileIcon': '', } }) else: return ({ 'error': { 'type': '', 'messege': 'Este correo no esta registrado en nuestros servidores' } }) return ({'error': {'type': '', 'messege': 'La contraseña no es correcta'}})
def getPost(): myId = request.form.get('id') limit = request.form.get('limit') nextPage = request.form.get('next') listPost = [] followList = getFollow(myId) followList.append(myId) if isBaned(myId): return { 'error': { 'type': 'ban-account', 'messege': 'Tu cuenta a sido baneada' } } for id in followList: for postsItem in post.select().where(post.idPosteador == id).limit( limit).offset(nextPage).execute(): userProps = user.select().where(user.id == id).execute() listPost.append({ 'post': { 'postId': postsItem.id, 'postMode': postsItem.videoMode, 'likes': 0, 'messege': postsItem.messege, 'date': postsItem.datePost, 'videoUrl': 'http://localhost:5000/video/{}/'.format(postsItem.id), 'reproductions': 0, 'comments': [], 'hashtags': postsItem.hashtags.split(' '), 'posteador': { 'id': postsItem.idPosteador, 'nickName': userProps[0].nickName, 'userName': userProps[0].userName, 'lastName': '', 'followers': '', 'rank': getRank(userProps[0].id), 'profileIcon': 'http://127.0.0.1:5000/get/imge/{}'.format(myId) } } }) return jsonify({ 'postNumber': len(listPost), 'next': int(nextPage) + int(limit), 'limit': limit, 'videos': listPost, 'status': getStatus(listPost) })