示例#1
0
    def get_corpus(self):
        users = self.__get_ddmal_users()
        self.__connect()

        self.curs.execute(CORPUS_QUERY)
        corpus = self.curs.fetchall()
        print "Deleting corpora"
        Corpus.objects.all().delete()

        print "Adding corpora"
        for corp in corpus:
            for user in users:
                if corp.get('creator') == user.get('uid'):
                    u = User.objects.get(username=user.get('name'))
                    break
            corp['creator'] = u

            corp['created'] = datetime.datetime.fromtimestamp(corp['created'])
            corp['updated'] = datetime.datetime.fromtimestamp(corp['updated'])
            x = Corpus(**corp)
            x.save()

        self.__disconnect()