def revisions(self, query={}, page=None, per_page=None, sort=1, project={'locale': 1, 'comment': 1, 'anon': 1, 'pageid': 1, 'tags': 1, 'timestamp': 1, 'userid': 1, 'revid': 1, 'contentformat': 1, 'contentmodel': 1, 'extraction_date': 1, 'parentid': 1, 'title': 1, '_id': 1, 'size': 1}):
        query = QueryHandler(db=self.db).get_query(query)
        if "_id" in query:
            query["_id"] = ObjectId(query["_id"])

        if sort == 'asc':
            sort = 1
        elif sort == 'desc':
            sort = -1

        if page==None or per_page==None:
            revisions= self.db.revisions.find(query, project).sort('timestamp', sort)
        else:
            revisions= self.db.revisions.find(query, project).skip((page-1)*per_page).limit(per_page).sort('timestamp', sort)

        result=[]
        for rev in revisions:

            if rev and 'timestamp' in rev:
                rev['timestamp']=rev['timestamp'].isoformat()

            if rev and 'extraction_date' in rev:
                rev['extraction_date']=rev['extraction_date'].isoformat()

            result.append(rev)
        return result
Ejemplo n.º 2
0
def mode_task(self,values,mode_attribute):

    db = RevisionDB(config={'host': config['default'].MONGO_HOST, 'port': config['default'].MONGO_PORT, 'username': config['default'].MONGO_USERNAME, 'password': config['default'].MONGO_PASSWORD, 'db_name':config['default'].MONGO_DB_NAME})
    #instantiate a new QueryHandler to get execute the corresponding function
    handler = QueryHandler(db=db)
    number = handler.get_mode(values,mode_attribute)
    if number!=None:
        return {'status': 'Task completed!',
        'result': "%s" % number}
    else:
        return {'status': 'Task failed!'}
Ejemplo n.º 3
0
def count_task(self,arguments):

    db = RevisionDB(config={'host': config['default'].MONGO_HOST, 'port': config['default'].MONGO_PORT, 'username': config['default'].MONGO_USERNAME, 'password': config['default'].MONGO_PASSWORD, 'db_name':config['default'].MONGO_DB_NAME})
    #instantiate a new QueryHandler to get execute the corresponding function
    handler = QueryHandler(db=db)
    number = handler.get_count(arguments)
    if number!=None:
        return {'status': 'Task completed!',
                'count': "%d" % number}
    else:
        return {'status': 'Task failed!'}
    def articles(self, query={}, page=None, per_page=None):
        query = QueryHandler(db=self.db).get_query(query)
        if "_id" in query:
            query["_id"] = ObjectId(query["_id"])

        if page == None or per_page == None:
            articles = self.db.articles.find(query)
        else:
            articles = self.db.articles.find(query).skip(
                (page - 1) * per_page).limit(per_page)

        result = []
        for rev in articles:
            rev['first_extraction_date'] = rev[
                'first_extraction_date'].isoformat()
            rev['last_extraction_date'] = rev[
                'last_extraction_date'].isoformat()
            result.append(rev)

        return result
    def articles(self, query={}, page=None, per_page=None, project={"pageid": 1, "title": 1, "locale": 1, "first_extraction_date": 1, "last_extraction_date": 1, "last_revision_extracted": 1, "ns": 1}):
        query = QueryHandler(db=self.db).get_query(query)
        if "_id" in query:
            query["_id"] = ObjectId(query["_id"])

        if page==None or per_page==None:
            articles= self.db.articles.find(query, project)
        else:
            articles= self.db.articles.find(query, project).skip((page-1)*per_page).limit(per_page)

        result=[]
        for rev in articles:
            if rev != None and 'first_extraction_date' in rev:
                rev['first_extraction_date']= rev['first_extraction_date'].isoformat()

            if rev != None and 'last_extraction_date' in rev:
                rev['last_extraction_date']= rev['last_extraction_date'].isoformat()

            result.append(rev)

        return result
    def revisions(self, query={}, page=None, per_page=None, sort=1):
        query = QueryHandler(db=self.db).get_query(query)
        if "_id" in query:
            query["_id"] = ObjectId(query["_id"])

        if sort == 'asc':
            sort = 1
        elif sort == 'desc':
            sort = -1

        if page == None or per_page == None:
            revisions = self.db.revisions.find(query).sort('timestamp', sort)
        else:
            revisions = self.db.revisions.find(query).skip(
                (page - 1) * per_page).limit(per_page).sort('timestamp', sort)

        result = []
        for rev in revisions:
            rev['timestamp'] = rev['timestamp'].isoformat()
            rev['extraction_date'] = rev['extraction_date'].isoformat()
            result.append(rev)
        return result