Ejemplo n.º 1
0
def do_get_list(db, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of twt citizen aliases
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {'authority': AUTHORITY}
    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    name_only = False
    if other and ('name_only' in other) and other['name_only']:
        try:
            name_only = bool(_get_boolean(other['name_only']))
        except:
            name_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not name_only:
            docs.append(entry)
        else:
            if (not 'identifiers' in entry):
                continue
            if type(entry['identifiers']) not in (list, tuple):
                continue
            if not len(entry['identifiers']):
                continue
            if not entry['identifiers'][0]:
                continue
            one_name = entry['identifiers'][0]
            if type(one_name) is not dict:
                continue

            source = None
            if ('sources' in entry) and (type(entry['sources']) is list):
                if len(entry['sources']) and (entry['sources'][0]):
                    source = entry['sources'][0]
            if source:
                one_name['source'] = source
            docs.append(one_name)

    return (True, docs, {'total': total})
Ejemplo n.º 2
0
def do_get_list(db, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of twt citizen aliases
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {'authority': AUTHORITY}
    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    name_only = False
    if other and ('name_only' in other) and other['name_only']:
        try:
            name_only = bool(_get_boolean(other['name_only']))
        except:
            name_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not name_only:
            docs.append(entry)
        else:
            if (not 'identifiers' in entry):
                continue
            if type(entry['identifiers']) is not dict:
                continue
            one_name = {}
            if 'user_id' in entry['identifiers']:
                one_name['user_id'] = entry['identifiers']['user_id']
            if 'user_name' in entry['identifiers']:
                one_name['user_name'] = entry['identifiers']['user_name']

            source = None
            if ('sources' in entry) and (type(entry['sources'])
                                         in (list, tuple)):
                if len(entry['sources']) and (entry['sources'][0]):
                    source = entry['sources'][0]
            if source:
                one_name['source'] = source
            docs.append(one_name)

    return (True, docs, {'total': total})
Ejemplo n.º 3
0
def do_get_list(db, offset, limit, sort, other):
    '''
    returns list of coverages
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {}

    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    name_only = False
    if other and ('name_only' in other) and other['name_only']:
        try:
            name_only = bool(_get_boolean(other['name_only']))
        except:
            name_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not name_only:
            docs.append(entry)
        else:
            if 'title' not in entry:
                continue

            one_name = {
                'title': entry['title'],
                FIELD_ACTIVE: None,
            }

            if FIELD_ACTIVE in entry:
                one_name[FIELD_ACTIVE] = entry[FIELD_ACTIVE]

            docs.append(one_name)

    return (True, docs, {'total': total})
Ejemplo n.º 4
0
def do_get_list(db,
                spec_type,
                spec_id,
                offset=None,
                limit=None,
                sort=None,
                other=None):
    '''
    returns data of a set of sms reports
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {'feed_type': FEED_TYPE}
    if 'session_id' == spec_type:
        list_spec['session'] = spec_id
    if 'sent_to' == spec_type:
        list_spec[
            'recipients.identifiers.user_id_search'] = normalize_phone_number(
                spec_id)
    if 'received_from' == spec_type:
        list_spec[
            'authors.identifiers.user_id_search'] = normalize_phone_number(
                spec_id)

    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    text_only = False
    if other and ('text_only' in other) and other['text_only']:
        try:
            text_only = bool(_get_boolean(other['text_only']))
        except:
            text_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not text_only:
            docs.append(entry)
        else:
            one_text = {'original': None, 'authors': None, 'recipients': None}
            authors = []
            recipients = []
            if 'original' in entry:
                one_text['original'] = entry['original']
            if ('authors' in entry) and (type(entry['authors'])
                                         in (list, tuple)):
                for one_author in entry['authors']:
                    if (type(one_author) is dict) and (
                            'identifiers'
                            in one_author) and (one_author['identifiers']):
                        one_alias_set = one_author['identifiers']
                        if type(one_alias_set) is dict:
                            if ('user_id' in one_alias_set
                                ) and one_alias_set['user_id']:
                                authors.append(one_alias_set['user_id'])
            if ('recipients' in entry) and (type(entry['recipients'])
                                            in (list, tuple)):
                for one_recipient in entry['recipients']:
                    if (type(one_recipient) is
                            dict) and ('identifiers' in one_recipient) and (
                                one_recipient['identifiers']):
                        one_alias_set = one_recipient['identifiers']
                        if type(one_alias_set) is dict:
                            if ('user_id' in one_alias_set
                                ) and one_alias_set['user_id']:
                                recipients.append(one_alias_set['user_id'])
            if authors:
                try:
                    one_text['authors'] = ', '.join(authors)
                except:
                    pass
            if recipients:
                try:
                    one_text['recipients'] = ', '.join(recipients)
                except:
                    pass
            if (not one_text['original']) and (not one_text['authors']) and (
                    not one_text['recipients']):
                continue

            docs.append(one_text)

    return (True, docs, {'total': total})
Ejemplo n.º 5
0
def do_get_list(db, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of sms citizen aliases
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {'authority': AUTHORITY}
    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    name_only = False
    if other and ('name_only' in other) and other['name_only']:
        try:
            name_only = bool(_get_boolean(other['name_only']))
        except:
            name_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not name_only:
            docs.append(entry)
        else:
            if (not 'identifiers' in entry):
                continue
            if type(entry['identifiers']) is not dict:
                continue
            one_name = {}
            if 'user_id' not in entry['identifiers']:
                continue
            one_name['phone_number'] = entry['identifiers']['user_id']
            if not one_name['phone_number']:
                continue

            description = None
            if ('description' in entry) and entry['description']:
                description = entry['description']
            if description:
                one_name['description'] = description
            name_list = []
            for name_key in ['name_first', 'name_last', 'name_full']:
                if (name_key in entry) and entry[name_key]:
                    name_list.append(entry[name_key])
            if name_list:
                one_name['names'] = ' - '.join(name_list)

            docs.append(one_name)

    return (True, docs, {'total': total})
Ejemplo n.º 6
0
def do_get_list(db, endpoint_type, endpoint_id, proto=None, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of reports saved by a stream or a search
    '''
    if not db:
        return (False, 'inner application error')

    endpoint_id = _get_id_value(endpoint_id)

    list_spec = {'feed_type': FEED_TYPE, 'channels': {'$elemMatch': {'type': endpoint_type, 'value': endpoint_id}}}
    if proto is not None:
        try:
            proto = bool(_get_boolean(proto))
        except:
            return (False, 'the "proto" specifier has to be a boolean value')
        list_spec['proto'] = proto

    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    text_only = False
    if other and ('text_only' in other) and other['text_only']:
        try:
            text_only = bool(_get_boolean(other['text_only']))
        except:
            text_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not text_only:
            docs.append(entry)
        else:
            if (not 'texts' in entry):
                continue
            if (not entry['texts']):
                continue
            if (type(entry['texts']) not in [list]):
                continue
            for one_text in entry['texts']:
                source = None
                if ('sources' in entry) and (type(entry['sources']) is list):
                    if len(entry['sources']) and (entry['sources'][0]):
                        source = entry['sources'][0]
                if source:
                    if (type(one_text) is dict):
                        one_text['source'] = source
                docs.append(one_text)

    return (True, docs, {'total': total})
Ejemplo n.º 7
0
def do_get_list(db, spec_type, spec_id, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of sms reports
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {'feed_type': FEED_TYPE}
    if 'session_id' == spec_type:
        list_spec['session'] = spec_id
    if 'sent_to' == spec_type:
        list_spec['recipients.identifiers.user_id_search'] = normalize_phone_number(spec_id)
    if 'received_from' == spec_type:
        list_spec['authors.identifiers.user_id_search'] = normalize_phone_number(spec_id)

    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    text_only = False
    if other and ('text_only' in other) and other['text_only']:
        try:
            text_only = bool(_get_boolean(other['text_only']))
        except:
            text_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not text_only:
            docs.append(entry)
        else:
            one_text = {
                'original': None,
                'authors': None,
                'recipients': None
            }
            authors = []
            recipients = []
            if 'original' in entry:
                one_text['original'] = entry['original']
            if ('authors' in entry) and (type(entry['authors']) in (list, tuple)):
                for one_author in entry['authors']:
                    if (type(one_author) is dict) and ('identifiers' in one_author) and (one_author['identifiers']):
                        one_alias_set = one_author['identifiers']
                        if type(one_alias_set) is dict:
                            if ('user_id' in one_alias_set) and one_alias_set['user_id']:
                                authors.append(one_alias_set['user_id'])
            if ('recipients' in entry) and (type(entry['recipients']) in (list, tuple)):
                for one_recipient in entry['recipients']:
                    if (type(one_recipient) is dict) and ('identifiers' in one_recipient) and (one_recipient['identifiers']):
                        one_alias_set = one_recipient['identifiers']
                        if type(one_alias_set) is dict:
                            if ('user_id' in one_alias_set) and one_alias_set['user_id']:
                                recipients.append(one_alias_set['user_id'])
            if authors:
                try:
                    one_text['authors'] = ', '.join(authors)
                except:
                    pass
            if recipients:
                try:
                    one_text['recipients'] = ', '.join(recipients)
                except:
                    pass
            if (not one_text['original']) and (not one_text['authors']) and (not one_text['recipients']):
                continue

            docs.append(one_text)

    return (True, docs, {'total': total})
Ejemplo n.º 8
0
def do_get_list(db, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of sms citizen aliases
    '''
    if not db:
        return (False, 'inner application error')

    list_spec = {'authority': AUTHORITY}
    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    name_only = False
    if other and ('name_only' in other) and other['name_only']:
        try:
            name_only = bool(_get_boolean(other['name_only']))
        except:
            name_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not name_only:
            docs.append(entry)
        else:
            if (not 'identifiers' in entry):
                continue
            if type(entry['identifiers']) is not dict:
                continue
            one_name = {}
            if 'user_id' not in entry['identifiers']:
                continue
            one_name['phone_number'] = entry['identifiers']['user_id']
            if not one_name['phone_number']:
                continue

            description = None
            if ('description' in entry) and entry['description']:
                description = entry['description']
            if description:
                one_name['description'] = description
            name_list = []
            for name_key in ['name_first', 'name_last', 'name_full']:
                if (name_key in entry) and entry[name_key]:
                    name_list.append(entry[name_key])
            if name_list:
                one_name['names'] = ' - '.join(name_list)

            docs.append(one_name)

    return (True, docs, {'total': total})
Ejemplo n.º 9
0
def do_get_list(db, endpoint_type, endpoint_id, proto=None, offset=None, limit=None, sort=None, other=None):
    '''
    returns data of a set of reports saved by a stream or a search
    '''
    if not db:
        return (False, 'inner application error')

    endpoint_id = _get_id_value(endpoint_id)

    list_spec = {'feed_type': FEED_TYPE, 'channels': {'$elemMatch': {'type': endpoint_type, 'value': endpoint_id}}}
    if proto is not None:
        try:
            proto = bool(_get_boolean(proto))
        except:
            return (False, 'the "proto" specifier has to be a boolean value')
        list_spec['proto'] = proto

    sort_list = _get_sort(sort)
    if not sort_list:
        sort_list = [('produced', 1)]

    text_only = False
    if other and ('text_only' in other) and other['text_only']:
        try:
            text_only = bool(_get_boolean(other['text_only']))
        except:
            text_only = False

    coll = db[collection]
    cursor = coll.find(list_spec).sort(sort_list)

    total = cursor.count()

    if limit is None:
        limit = DEFAULT_LIMIT

    if offset:
        cursor = cursor.skip(offset)
    if limit:
        cursor = cursor.limit(limit)

    docs = []
    for entry in cursor:
        if not entry:
            continue
        if not text_only:
            docs.append(entry)
        else:
            if (not 'texts' in entry):
                continue
            if (not entry['texts']):
                continue
            if (type(entry['texts']) not in [list]):
                continue
            for one_text in entry['texts']:
                source = None
                if ('sources' in entry) and (type(entry['sources']) in (list, tuple)):
                    if len(entry['sources']) and (entry['sources'][0]):
                        source = entry['sources'][0]
                if source:
                    if (type(one_text) is dict):
                        one_text['source'] = source
                docs.append(one_text)

    return (True, docs, {'total': total})