Beispiel #1
0
def posts_add(request):
    """Add a new bmark into the system given request params

    For example usage make sure to check out the unit tests in the
    test_delicious directory

    """
    params = request.params

    request.response.content_type = 'text/xml'
    if 'url' in params and params['url']:
        # check if we already have this
        try:
            mark = BmarkMgr.get_by_url(params['url'],
                                       username=request.user.username)

            mark.description = params.get('description', mark.description)
            mark.extended = params.get('extended', mark.extended)

            new_tags = params.get('tags', None)
            if new_tags:
                mark.update_tags(new_tags)

        except NoResultFound:
            # then let's store this thing
            # if we have a dt param then set the date to be that manual
            # date
            if 'dt' in request.params:
                # date format by delapi specs:
                # CCYY-MM-DDThh:mm:ssZ
                fmt = "%Y-%m-%dT%H:%M:%SZ"
                stored_time = datetime.strptime(request.params['dt'], fmt)
            else:
                stored_time = None

            mark = BmarkMgr.store(params['url'],
                                  request.user.username,
                                  params.get('description', ''),
                                  params.get('extended', ''),
                                  params.get('tags', ''),
                                  dt=stored_time,
                                  inserted_by="DELICIOUS_API")

        # if we have content, stick it on the object here
        if 'content' in request.params:
            content = StringIO(request.params['content'])
            content.seek(0)
            parsed = ReadContent.parse(content,
                                       content_type="text/html",
                                       url=mark.hashed.url)

            mark.readable = Readable()
            mark.readable.content = parsed.content
            mark.readable.content_type = parsed.content_type
            mark.readable.status_code = parsed.status
            mark.readable.status_message = parsed.status_message

        return '<result code="done" />'
    else:
        return '<result code="Bad Request: missing url" />'
Beispiel #2
0
def posts_get(request):
    """Return one or more bmarks based on search criteria

    Supported criteria:
    - url

    TBI:
    - tag={TAG}+{TAG}+
    - dt={CCYY-MM-DDThh:mm:ssZ}
    - hashes={MD5}+{MD5}+...+{MD5}

    """
    params = request.GET
    request.response_content_type = "text/xml"
    try:
        if "url" in params and params["url"]:
            url = request.GET["url"]
            bmark = BmarkMgr.get_by_url(url=url)

            if not bmark:
                return HTTPNotFound()

            # we need to escape any html entities in things
            return {"datefound": bmark.stored.strftime("%Y-%m-%d"), "posts": [bmark], "escape": escape}
        else:
            request.override_renderer = "string"
            return '<result code="Not Found" />'

    except NoResultFound:
        request.override_renderer = "string"
        return '<result code="Not Found" />'
Beispiel #3
0
def posts_get(request):
    """Return one or more bmarks based on search criteria

    Supported criteria:
    - url

    TBI:
    - tag={TAG}+{TAG}+
    - dt={CCYY-MM-DDThh:mm:ssZ}
    - hashes={MD5}+{MD5}+...+{MD5}

    """
    params = request.GET
    request.response_content_type = 'text/xml'
    try:
        if 'url' in params and params['url']:
            url = request.GET['url']
            bmark = BmarkMgr.get_by_url(url=url)

            if not bmark:
                return HTTPNotFound()

            # we need to escape any html entities in things
            return {
                'datefound': bmark.stored.strftime('%Y-%m-%d'),
                'posts': [bmark],
                'escape': escape,
            }
        else:
            request.override_renderer = 'string'
            return '<result code="Not Found" />'

    except NoResultFound:
        request.override_renderer = 'string'
        return '<result code="Not Found" />'
Beispiel #4
0
def posts_get(request):
    """Return one or more bmarks based on search criteria

    Supported criteria:
    - url

    TBI:
    - tag={TAG}+{TAG}+
    - dt={CCYY-MM-DDThh:mm:ssZ}
    - hashes={MD5}+{MD5}+...+{MD5}

    """
    params = request.params
    request.response.content_type = 'text/xml'
    LOG.debug(params)
    try:
        if 'url' in params and params['url']:
            url = request.params['url']
            LOG.debug(url)
            bmark = BmarkMgr.get_by_url(url=url, username=request.user.username)

            if not bmark:
                return HTTPNotFound()

            # we need to escape any html entities in things
            return {'datefound': bmark.stored.strftime('%Y-%m-%d'),
                    'posts': [bmark],
                    'escape': escape, }
        else:
            request.override_renderer = 'string'
            return '<result code="Not Found" />'

    except NoResultFound:
        request.override_renderer = 'string'
        return '<result code="Not Found" />'
Beispiel #5
0
def posts_add(request):
    """Add a new bmark into the system given request params

    For example usage make sure to check out the unit tests in the
    test_delicious directory

    """
    params = request.GET

    with Authorize(request.registry.settings.get('api_key', ''),
                   params.get('api_key', None)):

        request.response_content_type = 'text/xml'
        if 'url' in params and params['url']:
            # check if we already have this
            try:
                mark = BmarkMgr.get_by_url(params['url'])

                mark.description = params.get('description', mark.description)
                mark.extended = params.get('extended', mark.extended)

                new_tags = params.get('tags', None)
                if new_tags:
                    mark.update_tags(new_tags)

            except NoResultFound:
                # then let's store this thing

                # if we have a dt param then set the date to be that manual
                # date
                if 'dt' in request.params:
                    # date format by delapi specs:
                    # CCYY-MM-DDThh:mm:ssZ
                    fmt = "%Y-%m-%dT%H:%M:%SZ"
                    stored_time = datetime.strptime(request.params['dt'], fmt)
                else:
                    stored_time = None

                # we want to store fulltext info so send that along to the
                # import processor
                conn_str = request.registry.settings.get(
                    'sqlalchemy.url', False)
                fulltext = get_fulltext_handler(conn_str)

                BmarkMgr.store(
                    params['url'],
                    params.get('description', ''),
                    params.get('extended', ''),
                    params.get('tags', ''),
                    dt=stored_time,
                    fulltext=fulltext,
                )

            return '<result code="done" />'
        else:
            return '<result code="Bad Request: missing url" />'
Beispiel #6
0
def posts_add(request):
    """Add a new bmark into the system given request params

    For example usage make sure to check out the unit tests in the
    test_delicious directory

    """
    params = request.GET

    with Authorize(request.registry.settings.get("api_key", ""), params.get("api_key", None)):

        request.response_content_type = "text/xml"
        if "url" in params and params["url"]:
            # check if we already have this
            try:
                mark = BmarkMgr.get_by_url(params["url"])

                mark.description = params.get("description", mark.description)
                mark.extended = params.get("extended", mark.extended)

                new_tags = params.get("tags", None)
                if new_tags:
                    mark.update_tags(new_tags)

            except NoResultFound:
                # then let's store this thing

                # if we have a dt param then set the date to be that manual
                # date
                if "dt" in request.params:
                    # date format by delapi specs:
                    # CCYY-MM-DDThh:mm:ssZ
                    fmt = "%Y-%m-%dT%H:%M:%SZ"
                    stored_time = datetime.strptime(request.params["dt"], fmt)
                else:
                    stored_time = None

                # we want to store fulltext info so send that along to the
                # import processor
                conn_str = request.registry.settings.get("sqlalchemy.url", False)
                fulltext = get_fulltext_handler(conn_str)

                BmarkMgr.store(
                    params["url"],
                    params.get("description", ""),
                    params.get("extended", ""),
                    params.get("tags", ""),
                    dt=stored_time,
                    fulltext=fulltext,
                )

            return '<result code="done" />'
        else:
            return '<result code="Bad Request: missing url" />'
Beispiel #7
0
def edit_error(request):
    rdict = request.matchdict
    params = request.params
    post = request.POST

    with ReqAuthorize(request, username=rdict['username']):
        if 'new' in request.url:
            try:
                try:
                    bmark = BmarkMgr.get_by_url(post['url'])
                except:
                    bmark = None
                if bmark:
                    return {
                        'new': False,
                        'bmark': bmark,
                        'message': "URL already Exists",
                        'user': request.user,
                    }
                bmark = BmarkMgr.store(
                    post['url'],
                    request.user.username,
                    post['description'],
                    post['extended'],
                    post['tags'])

                # Assign a task to fetch this pages content and parse it out
                # for storage and indexing.
                DBSession.flush()
                tasks.fetch_bmark_content.delay(bmark.bid)

            except InvalidBookmark, exc:
                # There was an issue using the supplied data to create a new
                # bookmark. Send the data back to the user with the error
                # message.
                bmark = Bmark(
                    post['url'],
                    request.user.username,
                    desc=post['description'],
                    ext=post['extended'],
                    tags=post['tags'])

                return {
                    'new': True,
                    'bmark': bmark,
                    'message': exc.message,
                    'user': request.user,
                }

        else:
Beispiel #8
0
def posts_delete(request):
    """Remove a bmark from the system"""
    params = request.params
    request.response.content_type = 'text/xml'

    if 'url' in params and params['url']:
        try:
            bmark = BmarkMgr.get_by_url(params['url'],
                                        username=request.user.username)

            session = DBSession()
            session.delete(bmark)

            return '<result code="done" />'

        except NoResultFound:
            # if it's not found, then there's not a bookmark to delete
            return '<result code="Bad Request: bookmark not found" />'
Beispiel #9
0
def posts_delete(request):
    """Remove a bmark from the system"""
    params = request.params
    request.response.content_type = 'text/xml'

    if 'url' in params and params['url']:
        try:
            bmark = BmarkMgr.get_by_url(params['url'],
                                        username=request.user.username)

            session = DBSession()
            session.delete(bmark)

            return '<result code="done" />'

        except NoResultFound:
            # if it's not found, then there's not a bookmark to delete
            return '<result code="Bad Request: bookmark not found" />'
Beispiel #10
0
def posts_delete(request):
    """Remove a bmark from the system"""
    params = request.GET
    request.response_content_type = "text/xml"

    with Authorize(request.registry.settings.get("api_key", ""), params.get("api_key", None)):
        if "url" in params and params["url"]:
            try:
                bmark = BmarkMgr.get_by_url(params["url"])

                session = DBSession()
                session.delete(bmark)

                return '<result code="done" />'

            except NoResultFound:
                # if it's not found, then there's not a bookmark to delete
                return '<result code="Bad Request: bookmark not found" />'
Beispiel #11
0
def posts_delete(request):
    """Remove a bmark from the system"""
    params = request.GET
    request.response_content_type = 'text/xml'

    with Authorize(request.registry.settings.get('api_key', ''),
                   params.get('api_key', None)):
        if 'url' in params and params['url']:
            try:
                bmark = BmarkMgr.get_by_url(params['url'])

                session = DBSession()
                session.delete(bmark)

                return '<result code="done" />'

            except NoResultFound:
                # if it's not found, then there's not a bookmark to delete
                return '<result code="Bad Request: bookmark not found" />'
Beispiel #12
0
def bmark_add(request):
    """Add a new bookmark to the system"""
    rdict = request.matchdict
    if 'url' in request.params or 'hash_id' in request.params:
        params = request.params
    elif 'url' in request.json_body or 'hash_id' in request.json_body:
        params = request.json_body
    else:
        request.response.status_int = 400
        return {
            'error': 'Bad Request: missing url',
         }

    user = request.user

    if 'url' not in params and 'hash_id' not in rdict:
        request.response.status_int = 400
        return {
            'error': 'Bad Request: missing url',
         }

    elif 'hash_id' in rdict:
        try:
            mark = BmarkMgr.get_by_hash(rdict['hash_id'],
                                       username=user.username)
            mark = _update_mark(mark, params)

        except NoResultFound:
            request.response.status_code = 404
            return {
                'error': 'Bookmark with hash id {0} not found.'.format(
                            rdict['hash_id'])
            }

    else:
        # check if we already have this
        try:
            mark = BmarkMgr.get_by_url(params['url'],
                                       username=user.username)
            mark = _update_mark(mark, params)

        except NoResultFound:
            # then let's store this thing
            # if we have a dt param then set the date to be that manual
            # date
            if 'dt' in request.params:
                # date format by delapi specs:
                # CCYY-MM-DDThh:mm:ssZ
                fmt = "%Y-%m-%dT%H:%M:%SZ"
                stored_time = datetime.strptime(request.params['dt'], fmt)
            else:
                stored_time = None

            # check to see if we know where this is coming from
            inserted_by = params.get('inserted_by', 'unknown_api')

            mark = BmarkMgr.store(params['url'],
                         user.username,
                         params.get('description', ''),
                         params.get('extended', ''),
                         params.get('tags', ''),
                         dt=stored_time,
                         inserted_by=inserted_by,
                   )

        # we need to process any commands associated as well
        commander = Commander(mark)
        mark = commander.process()

        # if we have content, stick it on the object here
        if 'content' in params:
            content = StringIO(params['content'])
            content.seek(0)
            parsed = ReadContent.parse(content,
                                       content_type="text/html",
                                       url=mark.hashed.url)

            mark.readable = Readable()
            mark.readable.content = parsed.content
            mark.readable.content_type = parsed.content_type
            mark.readable.status_code = parsed.status
            mark.readable.status_message = parsed.status_message

        # we need to flush here for new tag ids, etc
        DBSession.flush()

        mark_data = dict(mark)
        mark_data['tags'] = [dict(mark.tags[tag]) for tag in mark.tags.keys()]

        return {
            'bmark': mark_data,
            'location': request.route_url('bmark_readable',
                                          hash_id=mark.hash_id,
                                          username=user.username),
        }
Beispiel #13
0
def posts_add(request):
    """Add a new bmark into the system given request params

    For example usage make sure to check out the unit tests in the
    test_delicious directory

    """
    params = request.params

    request.response.content_type = 'text/xml'
    if 'url' in params and params['url']:
        # check if we already have this
        try:
            mark = BmarkMgr.get_by_url(params['url'],
                                       username=request.user.username)

            mark.description = params.get('description', mark.description)
            mark.extended = params.get('extended', mark.extended)

            new_tags = params.get('tags', None)
            if new_tags:
                mark.update_tags(new_tags)

        except NoResultFound:
            # then let's store this thing
            # if we have a dt param then set the date to be that manual
            # date
            if 'dt' in request.params:
                # date format by delapi specs:
                # CCYY-MM-DDThh:mm:ssZ
                fmt = "%Y-%m-%dT%H:%M:%SZ"
                stored_time = datetime.strptime(request.params['dt'], fmt)
            else:
                stored_time = None

            mark = BmarkMgr.store(params['url'],
                         request.user.username,
                         params.get('description', ''),
                         params.get('extended', ''),
                         params.get('tags', ''),
                         dt=stored_time,
                         inserted_by="DELICIOUS_API"
                   )

        # if we have content, stick it on the object here
        if 'content' in request.params:
            content = StringIO(request.params['content'])
            content.seek(0)
            parsed = ReadContent.parse(content,
                                       content_type="text/html",
                                       url=mark.hashed.url)

            mark.readable = Readable()
            mark.readable.content = parsed.content
            mark.readable.content_type = parsed.content_type
            mark.readable.status_code = parsed.status
            mark.readable.status_message = parsed.status_message

        return '<result code="done" />'
    else:
        return '<result code="Bad Request: missing url" />'
Beispiel #14
0
def bmark_add(request):
    """Add a new bookmark to the system"""
    rdict = request.matchdict
    if 'url' in request.params or 'hash_id' in request.params:
        params = request.params
    elif 'url' in request.json_body or 'hash_id' in request.json_body:
        params = request.json_body
    else:
        request.response.status_int = 400
        return {
            'error': 'Bad Request: missing url',
        }

    user = request.user

    if 'url' not in params and 'hash_id' not in rdict:
        request.response.status_int = 400
        return {
            'error': 'Bad Request: missing url',
        }

    elif 'hash_id' in rdict:
        try:
            mark = BmarkMgr.get_by_hash(rdict['hash_id'],
                                        username=user.username)
            mark = _update_mark(mark, params)

        except NoResultFound:
            request.response.status_code = 404
            return {
                'error':
                'Bookmark with hash id {0} not found.'.format(rdict['hash_id'])
            }

    else:
        # check if we already have this
        try:
            mark = BmarkMgr.get_by_url(params['url'], username=user.username)
            mark = _update_mark(mark, params)

        except NoResultFound:
            # then let's store this thing
            # if we have a dt param then set the date to be that manual
            # date
            if 'dt' in request.params:
                # date format by delapi specs:
                # CCYY-MM-DDThh:mm:ssZ
                fmt = "%Y-%m-%dT%H:%M:%SZ"
                stored_time = datetime.strptime(request.params['dt'], fmt)
            else:
                stored_time = None

            # check to see if we know where this is coming from
            inserted_by = params.get('inserted_by', 'unknown_api')

            mark = BmarkMgr.store(
                params['url'],
                user.username,
                params.get('description', ''),
                params.get('extended', ''),
                params.get('tags', ''),
                dt=stored_time,
                inserted_by=inserted_by,
            )

        # we need to process any commands associated as well
        commander = Commander(mark)
        mark = commander.process()

        # if we have content, stick it on the object here
        if 'content' in params:
            content = StringIO(params['content'])
            content.seek(0)
            parsed = ReadContent.parse(content,
                                       content_type="text/html",
                                       url=mark.hashed.url)

            mark.readable = Readable()
            mark.readable.content = parsed.content
            mark.readable.content_type = parsed.content_type
            mark.readable.status_code = parsed.status
            mark.readable.status_message = parsed.status_message

        # we need to flush here for new tag ids, etc
        DBSession.flush()

        mark_data = dict(mark)
        mark_data['tags'] = [dict(mark.tags[tag]) for tag in mark.tags.keys()]

        return {
            'bmark':
            mark_data,
            'location':
            request.route_url('bmark_readable',
                              hash_id=mark.hash_id,
                              username=user.username),
        }
Beispiel #15
0
def posts_add(request):
    """Add a new bmark into the system given request params

    For example usage make sure to check out the unit tests in the
    test_delicious directory

    """
    params = request.params

    with Authorize(request.registry.settings.get('api_key', ''),
                   params.get('api_key', None)):

        request.response_content_type = 'text/xml'
        if 'url' in params and params['url']:
            # check if we already have this
            try:
                mark = BmarkMgr.get_by_url(params['url'])

                mark.description = params.get('description', mark.description)
                mark.extended = params.get('extended', mark.extended)

                new_tags = params.get('tags', None)
                if new_tags:
                    mark.update_tags(new_tags)

            except NoResultFound:
                # then let's store this thing
                # if we have a dt param then set the date to be that manual
                # date
                if 'dt' in request.params:
                    # date format by delapi specs:
                    # CCYY-MM-DDThh:mm:ssZ
                    fmt = "%Y-%m-%dT%H:%M:%SZ"
                    stored_time = datetime.strptime(request.params['dt'], fmt)
                else:
                    stored_time = None

                # we want to store fulltext info so send that along to the
                # import processor
                conn_str = request.registry.settings.get('sqlalchemy.url',
                                                         False)
                fulltext = get_fulltext_handler(conn_str)

                mark = BmarkMgr.store(params['url'],
                             params.get('description', ''),
                             params.get('extended', ''),
                             params.get('tags', ''),
                             dt=stored_time,
                             fulltext=fulltext,
                       )

            # if we have content, stick it on the object here
            if 'content' in request.params:
                content = StringIO(request.params['content'])
                content.seek(0)
                parsed = ReadContent.parse(content, content_type="text/html")

                mark.hashed.readable = Readable()
                mark.hashed.readable.content = parsed.content
                mark.hashed.readable.content_type = parsed.content_type
                mark.hashed.readable.status_code = parsed.status
                mark.hashed.readable.status_message = parsed.status_message


            return '<result code="done" />'
        else:
            return '<result code="Bad Request: missing url" />'