Example #1
0
        return new_tags

    def clear_tags(self, labels, save=True):
        """Delete all tags matching any of the provided labels.

        :param list labels: Labels of tags to delete
        :param bool save: Save record after update
        """
        self.tags = [tag for tag in self.tags if tag['label'] not in labels]
        if save:
            self.save()


lrecord_fields = ['TI', 'JT', 'FAU']


@Article.subscribe('before_save')
def update_lrecord(schema, instance):
    lrecord = {
        key: instance.record[key]
        for key in lrecord_fields if key in instance.record
    }
    instance._lrecord = util.apply_recursive(
        lambda value: value.lower() if hasattr(value, 'lower') else value,
        lrecord,
    )


Article.set_storage(storage.MongoStorage(mongo, 'article'))
Example #2
0
        'optimistic': True,
        'log_level': logging.DEBUG,
    }


import os
try:
    os.remove('db_blog.pkl')
except:
    pass
try:
    os.remove('db_tag.pkl')
except:
    pass

Tag.set_storage(storage.MongoStorage(db, 'tag'))
Blog.set_storage(storage.MongoStorage(db, 'blog'))
# Tag.set_storage(storage.PickleStorage('tag'))
# Blog.set_storage(storage.PickleStorage('blog'))

tag1 = Tag(value=str(random.randint(0, 1000)),
           count='count_1',
           keywords=['keywd1', 'keywd3', 'keywd4'])
tag1.save()

tag2 = Tag(value=str(random.randint(0, 1000)),
           count="count_2",
           misc="foobar",
           misc2="a")
tag2.save()
Example #3
0
            elm.extract()

        # Extract text
        text = ''.join(soup.findAll(text=True))

        # Unescape HTML
        text = parser.unescape(text)

        self.save_extract(text)

        # Update document
        self.save()

        return text

HTMLDocument.set_storage(storage.MongoStorage(mongo, 'htmldocument'))

class PDFDocument(Document):

    extract_method = fields.StringField()

    def read(self, overwrite=False):

        # Read from extracted file if exists
        if not overwrite:
            if self.extract_filepath and os.path.exists(self.extract_filepath):
                return to_unicode(open(self.extract_filepath).read())

        if not self.filepath or not os.path.exists(self.filepath):
            return
Example #4
0
    last = fields.StringField()
    first = fields.StringField()
    middle = fields.StringField()
    suffix = fields.StringField()
    _full = fields.StringField()
    _lfull = fields.StringField(index=True)

    def update_name_parts(self, fullname):
        human_name = nameparser.HumanName(fullname)
        for attr in name_parts:
            value = getattr(human_name, attr) or None
            setattr(self, attr, value)

    def update_fullname(self):
        human_name = nameparser.HumanName('')
        for attr in name_parts:
            value = getattr(self, attr) or ''
            setattr(human_name, attr, value)
        self._full = unicode(human_name)
        self._lfull = self._full.lower()


@Author.subscribe('before_save')
def update_fullname(schema, instance):
    instance.update_fullname()


Author.set_storage(storage.MongoStorage(mongo, 'author'))