def post(self):

        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('user_id', type=str, required=True, location='json')
        arg_parser.add_argument('email', type=str, location='json')
        arg_parser.add_argument('username', type=str, location='json')
        arg_parser.add_argument('first_name', type=str, location='json')
        arg_parser.add_argument('bio', type=str, location='json')
        arg_parser.add_argument('password', type=str, location='json')
        arg_parser.add_argument('user_title', type=str, location='json')
        arg_parser.add_argument('user_type', type=int, choices=[-1, 0, 2], location='json')
        arg_parser.add_argument('gender', type=str, choices=['M', 'F'], location='json')

        arg_parser.add_argument('profile_picture', type=file, location='files')
        arg_parser.add_argument('profile_video', type=file, location='files')
        args = arg_parser.parse_args()

        try:
            return admin_controllers.user_edit( current_user_id=current_user.id,
                                                user_id=args['user_id'],
                                                email=args['email'],
                                                username=args['username'],
                                                first_name=args['first_name'],
                                                bio=args['bio'],
                                                password=args['password'],
                                                user_title=args['user_title'],
                                                user_type=args['user_type'],
                                                profile_picture=args['profile_picture'],
                                                profile_video=args['profile_video'])
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def get(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('offset', type=int, default=0, location='args')
        arg_parser.add_argument('limit', type=int, default=10, location='args')
        arg_parser.add_argument('user_type', type=int, default=2, location='args')
        arg_parser.add_argument('deleted', type=int, default=0, location='args')
        arg_parser.add_argument('order_by', type=str, default='user_since', choices=['user_since', 'name'], location='args')
        arg_parser.add_argument('desc', type=int, default=1, choices=[1, 0], location='args')
        arg_parser.add_argument('since_time', type=int,default=admin_controllers.maketimestamp(datetime(2001,1,1)), location='args')

        
        try:
            args = arg_parser.parse_args()
            return admin_controllers.user_list(offset=args['offset'],
                                                    limit=args['limit'],
                                                    user_type=bool(args['user_type']),
                                                    deleted=bool(args['deleted']),
                                                    order_by=args['order_by'],
                                                    desc=bool(args['desc']),
                                                    since_time=datetime.fromtimestamp(args['since_time'])
                                                    )
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
 def get(self,query):
     try:
         return admin_controllers.get_celeb_search(query)
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
 def get(self):
     arg_parser = reqparse.RequestParser()
     arg_parser.add_argument('question_id',required=True, location='args', type=str)
     args = arg_parser.parse_args()
     try:
         return admin_controllers.get_similar_questions(args['question_id'])
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
def _encode_video_to_profile(file_path, video_url, profile, log_id, username=''):
    if video_db.video_already_encoded(video_url=video_url, video_quality=profile):
        print 'Not Retrying now.'
        return
    result = video_encoder.encode_video_to_profile(file_path, video_url, profile, username)
    video_db.update_video_encode_log_finish(log_id, result)
    video_db.update_video_state(video_url, result)

    #if low was not made make try for medium
    if profile == 'low' and not result:
        log_id = video_db.add_video_encode_log_start(video_url=video_url, video_quality='medium')
        _encode_video_to_profile(file_path, video_url, 'medium', log_id, username=username)

    if result:
        try:
            post_id = video_db.get_post_id_from_video(video_url)
            if post_id:
                notification.post_notifications(post_id)
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0], err[1], err[2])
            print traceback.format_exc(e)

    #Post to facebook hook

    if result:
        try:
            post_id = video_db.get_post_id_from_video(video_url)
            if post_id:
                post = Post.query.filter(Post.id==post_id).one()
                question = Question.query.filter(Question.id==post.question)
                user = User.query.filter(User.id == post.answer_author)

                redis_key = str(user.id)+'_'+str(question.id)

                perms_data = redis_post_perms.get(redis_key)
                if perms_data:
                    permissions = json.loads(perms_data)
            if post_id and permissions.get('post_facebook') and user.facebook_write_permission:
                message = "I just answered a question on FranklyMe"
                post_name = "Frankster's Answer"
                post_link = 'www.frankly.me/p/{0}'.format(question.short_id)
                post_caption = "Question Answered by {0}".format(user.first_name)
                post_description = "Question : {0}".format(question.body)
                post_picture = post.thumbnail_url
                access_token = user.facebook_token
                publish_to_facebook(message, post_name, post_link, post_caption, post_description, post_picture, access_token = access_token)
                #post response to facebook
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0], err[1], err[2])
            print traceback.format_exc(e)

    db.engine.dispose()
 def post(self):
     arg_parser = reqparse.RequestParser()
     arg_parser.add_argument('question_id', type=str, default=0, location='json')
     args = arg_parser.parse_args()
     try:
         return admin_controllers.question_undelete( current_user_id=current_user.id,
                                                     question_id=args['question_id'])
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
 def post(self):
     arg_parser = reqparse.RequestParser()
     arg_parser.add_argument('item_type', type=str, location='json', required = True, choices=['post', 'user', 'question'])
     arg_parser.add_argument('item_id', type=str, location='json', required = True)
     args = arg_parser.parse_args()
     try:
         return admin_controllers.delete_from_central_queue(args['item_type'], args['item_id'])
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
 def get(self):
     arg_parser = reqparse.RequestParser()
     arg_parser.add_argument('offset', type=int, location='args', default=0)
     arg_parser.add_argument('limit', type=int, location='args', default=10)
     args = arg_parser.parse_args()
     try:
         return admin_controllers.get_celebs_asked_today(args['offset'], args['limit'])
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
 def get(self,offset, limit):
     try:
         arg_parser = reqparse.RequestParser()
         arg_parser.add_argument('since_time', type=int,default=admin_controllers.maketimestamp(datetime.datetime(2001,1,1)), location='args')
     
         args = arg_parser.parse_args()
     
         return admin_controllers.get_celeb_list(offset, limit,datetime.fromtimestamp(args['since_time']))
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
    def post(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('primary_question_id', type=str, required=True, location='json')
        arg_parser.add_argument('questions_to_redirect', type=list, required = True, location = 'json')
        args = arg_parser.parse_args()

        try:
            return admin_controllers.questions_redirect(args['primary_question_id'], args['questions_to_redirect'])
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def post(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('category_name', type=str, required=True, location='json')
        arg_parser.add_argument('cat_user_data', type=list, required = True, location = 'json')
        args = arg_parser.parse_args()

        try:
            return admin_controllers.update_category_order_search_default(args['category_name'], args['cat_user_data'])
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
 def post(self):
     arg_parser = reqparse.RequestParser()
     arg_parser.add_argument('post_id', type=str, required=True, location='form')
     arg_parser.add_argument('video', type=file, required=True, location='files')
     args = arg_parser.parse_args()
     try:
         return admin_controllers.post_edit(current_user_id=current_user.id, 
                                             post_id=args['post_id'],
                                             video=args['video'])
     except Exception as e:
         err = sys.exc_info()
         raygun.send(err[0],err[1],err[2])
         print traceback.format_exc(e)
         abort(500, message='Error')
Exemple #13
0
 def process(self,func):
     m = self.q.read()
     if m:
         try:
             return_code = func(json.loads(m.get_body()))
             if return_code == 0:
                 m.delete()
             return return_code
         except Exception as e:
             exc_type, exc_value, exc_traceback = sys.exc_info()
             raygun.send(exc_type, exc_value, exc_traceback)
             return -1
             print "Message retained in queue because of", e
     return 1
    def get(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('user_id', type=str, required = True, location = 'args')
        arg_parser.add_argument('offset', type=int, default=0, location = 'args')
        arg_parser.add_argument('limit', type=int, default=5, location = 'args')
        args = arg_parser.parse_args()
        print args

        try:
            return admin_controllers.get_unanswered_questions_with_same_count(args['user_id'], args['offset'], args['limit'])
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def post(self):
        from flask import request
        print request.json

        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('items', type=list, location='json', required = True)
        args = arg_parser.parse_args()
        print args
        try:
            return admin_controllers.update_que_order(args['items'])
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def post(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('user_id', type=str, required=True, location='args')
        arg_parser.add_argument('start_time' , type=int, default=0, location='args')
        arg_parser.add_argument('end_time', type=int,default=99999999999, location='args')
        args = arg_parser.parse_args()

        try:
            return admin_controllers.get_user_activity_timeline(user_id=args['user_id'],
                                                                start_time=args['start_time'],
                                                                end_time=args['end_time'])
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def post(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('question_id', type=str, required=True, location='json')
        arg_parser.add_argument('change_count', type=int, required=True, location='json')

        args = arg_parser.parse_args()
        try:
            return admin_controllers.question_change_upvotes(
                                                                question_id=args['question_id'],
                                                                change_count=args['change_count']
                                                            )
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def post(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('question_to', type=str,location = 'json', required = True)
        arg_parser.add_argument('question_author', type=str,location = 'json', default = None)
        arg_parser.add_argument('question_body', type=str,location = 'json', required = True)
        arg_parser.add_argument('gender', type=str, location ='json', choices=['M', 'F'])

        args = arg_parser.parse_args()
        try:
            return admin_controllers.question_add(  current_user_id=current_user.id,
                                                    question_to=args['question_to'],
                                                    body=args['question_body'],
                                                    question_author=args['question_author'],
                                                    question_author_gender=args.get('gender'))
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def get(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('offset', type=int, default=0, location='args')
        arg_parser.add_argument('limit', type=int, default=10, location='args')
        arg_parser.add_argument('public', type=int, default=1, location='args')
        arg_parser.add_argument('deleted', type=int, default=0, location='args')
        try:

            args = arg_parser.parse_args()
        
            return admin_controllers.question_list(offset=args['offset'],
                                                    limit=args['limit'],
                                                    public=bool(args['public']),
                                                    deleted=bool(args['deleted'])
                                                    )
        except Exception as e:
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message='Error')
    def post(self):
        arg_parser = reqparse.RequestParser()
        arg_parser.add_argument('email', type=str, required=True, location='form')
        arg_parser.add_argument('username', type=str, required=True, location='form')
        arg_parser.add_argument('first_name', type=str, required=True, location='form')
        arg_parser.add_argument('bio', type=str, required=True, location='form')
        arg_parser.add_argument('password', type=str, required=True, location='form')
        arg_parser.add_argument('user_title', type=str, location='form')
        arg_parser.add_argument('user_type', type=int, default=-1, choices=[-1, 0, 2], location='form')
        arg_parser.add_argument('gender', type=str, choices=['M', 'F'], location='form')

        arg_parser.add_argument('profile_picture', type=file, location='files')
        arg_parser.add_argument('profile_video', type=file, location='files')
        args = arg_parser.parse_args()
        print 'bhonsdi wala.'

        try:
            return admin_controllers.user_add(  current_user_id=current_user.id,
                                                email=args['email'],
                                                username=args['username'],
                                                first_name=args['first_name'],
                                                bio=args['bio'],
                                                password=args['password'],
                                                user_title=args['user_title'],
                                                user_type=args['user_type'],
                                                gender=args['gender'],
                                                profile_picture=args['profile_picture'],
                                                profile_video=args['profile_video']
                                                )
        except CustomExceptions.UserAlreadyExistsException as e:
            abort(409, message=str(e))

        except Exception as e:
            print 'Hellllllo'
            err = sys.exc_info()
            raygun.send(err[0],err[1],err[2])
            print traceback.format_exc(e)
            abort(500, message=str(e))