Exemplo n.º 1
0
def feed_twt_authorized_post_one():
    from citizendesk.feeds.twt.authorized import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    try:
        data = request.get_json(True, False, False)
        if type(data) is not dict:
            data = None
    except:
        data = None
    if data is None:
        try:
            data = request.json
            if type(data) is not dict:
                data = None
        except:
            data = None
    if data is None:
        return (json.dumps('provided data are not valid json'), 404, {'Content-Type': 'application/json'})

    auther_url = get_config('newstwister_url')

    res = process.do_post_one(mongo_dbs.get_db().db, auther_url, data)

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 404, {'Content-Type': 'application/json'})

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 200, {'Content-Type': 'application/json'})
Exemplo n.º 2
0
def feed_twt_stream_patch_one_emulate(stream_id, switch_on):
    from citizendesk.feeds.twt.stream import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    data = {
        'control': {
            'streamer_url': get_config('newstwister_url'),
            'switch_on': switch_on
        },
    }

    params = {'force': True}

    res = process.do_patch_one(mongo_dbs.get_db().db, stream_id, data,
                               params['force'])

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default,
                           sort_keys=True), 404, {
                               'Content-Type': 'application/json'
                           })

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default,
                       sort_keys=True), 200, {
                           'Content-Type': 'application/json'
                       })
Exemplo n.º 3
0
def feed_twt_citizen_alias_request_one(alias_type, alias_value):
    from citizendesk.feeds.twt.citizen_alias import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    searcher_url = get_config('newstwister_url')

    res = process.do_request_one(mongo_dbs.get_db().db, searcher_url,
                                 alias_type, alias_value)

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        if 2 < len(res):
            ret_data['_meta']['reason'] = res[2]
        return (json.dumps(ret_data, default=json_util.default,
                           sort_keys=True), 404, {
                               'Content-Type': 'application/json'
                           })

    ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
    return (json.dumps(ret_data, default=json_util.default,
                       sort_keys=True), 200, {
                           'Content-Type': 'application/json'
                       })
Exemplo n.º 4
0
def feed_twt_send_one_post(report_id):
    from citizendesk.feeds.twt.send import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    try:
        data = request.get_json(True, False, False)
        if type(data) is not dict:
            data = None
    except:
        data = None
    if data is None:
        try:
            data = request.json
            if type(data) is not dict:
                data = None
        except:
            data = None
    if data is None:
        return (json.dumps('provided data are not valid json'), 404, {
            'Content-Type': 'application/json'
        })

    try:
        authorized_id = data['authorized_id']
        user_id = data['user_id']
        endpoint_id = data['endpoint_id']
        tweet_spec = data['tweet_spec']
    except:
        return (json.dumps(
            'provided data should contain "authorized_id", "user_id", "endpoint_id", "tweet_spec" parts'
        ), 404, {
            'Content-Type': 'application/json'
        })

    sender_url = get_config('newstwister_url')

    res = process.do_post_send(mongo_dbs.get_db().db, sender_url,
                               authorized_id, user_id, endpoint_id, tweet_spec,
                               report_id)

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default,
                           sort_keys=True), 404, {
                               'Content-Type': 'application/json'
                           })

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default,
                       sort_keys=True), 200, {
                           'Content-Type': 'application/json'
                       })
Exemplo n.º 5
0
def feed_twt_citizen_alias_get_one(alias_type, alias_value):
    from citizendesk.feeds.twt.citizen_alias import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    other = {'force': None}
    for key in other:
        if key in request.args:
            other[key] = request.args.get(key)

    force = False
    if other and ('force' in other):
        force = _get_boolean(other['force'])

    res = process.do_get_one(mongo_dbs.get_db().db, alias_type, alias_value)

    err_reason = None
    err_msg = None
    if not res[0]:
        err_msg = res[1]

    if (not res[0]) and force:
        err_msg = res[1]
        searcher_url = get_config('newstwister_url')
        res_aux = process.do_request_one(mongo_dbs.get_db().db, searcher_url,
                                         alias_type, alias_value)
        if not res_aux[0]:
            err_msg = res_aux[1]
            if 2 < len(res_aux):
                err_reason = res_aux[2]
        else:
            res = process.do_get_one(mongo_dbs.get_db().db, alias_type,
                                     alias_value)
            if not res[0]:
                err_msg = res_aux[1]
                err_reason = None

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': err_msg}}
        if err_reason:
            ret_data['_meta']['reason'] = err_reason
        return (json.dumps(ret_data, default=json_util.default,
                           sort_keys=True), 404, {
                               'Content-Type': 'application/json'
                           })

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default,
                       sort_keys=True), 200, {
                           'Content-Type': 'application/json'
                       })
Exemplo n.º 6
0
def feed_twt_stream_patch_one(stream_id):
    from citizendesk.feeds.twt.stream import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    try:
        data = request.get_json(True, False, False)
        if type(data) is not dict:
            data = None
    except:
        data = None
    if data is None:
        try:
            data = request.json
            if type(data) is not dict:
                data = None
        except:
            data = None
    if data is None:
        return (json.dumps('provided data are not valid json'), 404, {
            'Content-Type': 'application/json'
        })

    if ('streamer_url' not in data) or (not data['streamer_url']):
        data['streamer_url'] = get_config('newstwister_url')

    params = {'force': None}
    for key in params:
        if key in request.args:
            params[key] = request.args.get(key)

    res = process.do_patch_one(mongo_dbs.get_db().db, stream_id, data,
                               params['force'])

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default,
                           sort_keys=True), 404, {
                               'Content-Type': 'application/json'
                           })

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default,
                       sort_keys=True), 200, {
                           'Content-Type': 'application/json'
                       })
Exemplo n.º 7
0
def feed_twt_citizen_alias_get_one(alias_type, alias_value):
    from citizendesk.feeds.twt.citizen_alias import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    other = {'force': None}
    for key in other:
        if key in request.args:
            other[key] = request.args.get(key)

    force = False
    if other and ('force' in other):
        force = _get_boolean(other['force'])

    res = process.do_get_one(mongo_dbs.get_db().db, alias_type, alias_value)

    err_reason = None
    err_msg = None
    if not res[0]:
        err_msg = res[1]

    if (not res[0]) and force:
        err_msg = res[1]
        searcher_url = get_config('newstwister_url')
        res_aux = process.do_request_one(mongo_dbs.get_db().db, searcher_url, alias_type, alias_value)
        if not res_aux[0]:
            err_msg = res_aux[1]
            if 2 < len(res_aux):
                err_reason = res_aux[2]
        else:
            res = process.do_get_one(mongo_dbs.get_db().db, alias_type, alias_value)
            if not res[0]:
                err_msg = res_aux[1]
                err_reason = None

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': err_msg}}
        if err_reason:
            ret_data['_meta']['reason'] = err_reason
        return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 404, {'Content-Type': 'application/json'})

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 200, {'Content-Type': 'application/json'})
Exemplo n.º 8
0
def feed_twt_citizen_alias_request_one(alias_type, alias_value):
    from citizendesk.feeds.twt.citizen_alias import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    searcher_url = get_config('newstwister_url')

    res = process.do_request_one(mongo_dbs.get_db().db, searcher_url, alias_type, alias_value)

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        if 2 < len(res):
            ret_data['_meta']['reason'] = res[2]
        return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 404, {'Content-Type': 'application/json'})

    ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
    return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 200, {'Content-Type': 'application/json'})
Exemplo n.º 9
0
def feed_twt_authorized_finalize_one(doc_id):
    from citizendesk.feeds.twt.authorized import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    try:
        data = request.get_json(True, False, False)
        if type(data) is not dict:
            data = None
    except:
        data = None
    if data is None:
        try:
            data = request.json
            if type(data) is not dict:
                data = None
        except:
            data = None
    if data is None:
        return (json.dumps('provided data are not valid json'), 404, {
            'Content-Type': 'application/json'
        })

    auther_url = get_config('newstwister_url')

    res = process.do_finalize_one(mongo_dbs.get_db().db, auther_url, doc_id,
                                  data)

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default,
                           sort_keys=True), 404, {
                               'Content-Type': 'application/json'
                           })

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default,
                       sort_keys=True), 200, {
                           'Content-Type': 'application/json'
                       })
Exemplo n.º 10
0
def feed_twt_search_one_post():
    from citizendesk.feeds.twt.search import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    try:
        data = request.get_json(True, False, False)
        if type(data) is not dict:
            data = None
    except:
        data = None
    if data is None:
        try:
            data = request.json
            if type(data) is not dict:
                data = None
        except:
            data = None
    if data is None:
        return (json.dumps('provided data are not valid json'), 404, {'Content-Type': 'application/json'})

    try:
        user_id = data['user_id']
        request_id = data['request_id']
        search_spec = data['search_spec']
    except:
        return (json.dumps('provided data should contain "user_id", "request_id", "search_spec" parts'), 404, {'Content-Type': 'application/json'})

    searcher_url = get_config('newstwister_url')
    if ('searcher_url' in data) and data['searcher_url']:
        searcher_url = data['searcher_url']

    res = process.do_post_search(mongo_dbs.get_db().db, searcher_url, user_id, request_id, search_spec)

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 404, {'Content-Type': 'application/json'})

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 200, {'Content-Type': 'application/json'})
Exemplo n.º 11
0
def feed_twt_stream_patch_one(stream_id):
    from citizendesk.feeds.twt.stream import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    try:
        data = request.get_json(True, False, False)
        if type(data) is not dict:
            data = None
    except:
        data = None
    if data is None:
        try:
            data = request.json
            if type(data) is not dict:
                data = None
        except:
            data = None
    if data is None:
        return (json.dumps('provided data are not valid json'), 404, {'Content-Type': 'application/json'})

    if ('streamer_url' not in data) or (not data['streamer_url']):
        data['streamer_url'] = get_config('newstwister_url')

    params = {'force': None}
    for key in params:
        if key in request.args:
            params[key] = request.args.get(key)

    res = process.do_patch_one(mongo_dbs.get_db().db, stream_id, data, params['force'])

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 404, {'Content-Type': 'application/json'})

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 200, {'Content-Type': 'application/json'})
Exemplo n.º 12
0
def feed_twt_stream_patch_one_emulate(stream_id, switch_on):
    from citizendesk.feeds.twt.stream import process
    from citizendesk.feeds.config import get_config

    logger = get_logger()
    client_ip = get_client_ip()

    data = {
        'control': {
            'streamer_url': get_config('newstwister_url'),
            'switch_on': switch_on
        },
    }

    params = {'force': True}

    res = process.do_patch_one(mongo_dbs.get_db().db, stream_id, data, params['force'])

    if not res[0]:
        ret_data = {'_meta': {'schema': process.schema, 'message': res[1]}}
        return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 404, {'Content-Type': 'application/json'})

    ret_data = {'_meta': {'schema': process.schema}, '_data': res[1]}
    return (json.dumps(ret_data, default=json_util.default, sort_keys=True), 200, {'Content-Type': 'application/json'})