当前位置: 首页>>代码示例>>Python>>正文


Python Declaration.init方法代码示例

本文整理汇总了Python中catalog.elastic_models.Declaration.init方法的典型用法代码示例。如果您正苦于以下问题:Python Declaration.init方法的具体用法?Python Declaration.init怎么用?Python Declaration.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在catalog.elastic_models.Declaration的用法示例。


在下文中一共展示了Declaration.init方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: handle

# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import init [as 别名]
    def handle(self, *args, **options):
        try:
            file_path = args[0]
        except IndexError:
            raise CommandError('First argument must be a source file')

        with open(file_path, 'r', newline='', encoding='utf-8') as source:
            decls = json.load(source)

            counter = 0
            Declaration.init()  # Apparently this is required to init mappings
            for row in decls:
                mapped = self.map_fields(row)
                res = Declaration.search().filter(
                    Term(general__last_name=mapped[
                        'general']['last_name'].lower().split('-')) &
                    Term(general__name=mapped[
                        'general']['name'].lower().split('-')) &
                    Term(intro__declaration_year=mapped[
                        'intro']['declaration_year'])
                )

                if mapped['general']['patronymic']:
                    res = res.filter(Term(general__patronymic=mapped[
                        'general']['patronymic'].lower()))

                res = res.execute()

                if not res.hits:
                    item = Declaration(**mapped)
                    item.save()
                    counter += 1
            self.stdout.write(
                'Loaded {} items to persistence storage'.format(counter))
开发者ID:excieve,项目名称:declarations.com.ua,代码行数:36,代码来源:loadchesno.py

示例2: handle

# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import init [as 别名]
    def handle(self, *args, **options):
        try:
            file_path = args[0]
            id_prefix = args[1]
        except IndexError:
            raise CommandError(
                'First argument must be a source file and second is a id prefix')

        groups = defaultdict(list)
        with open(file_path, 'r', newline='', encoding='utf-8') as source:
            reader = csv.DictReader(source, delimiter=',')
            counter = 0
            for row in reader:
                status_col = 'Status' if 'Status' in row else 'Статус'
                if row[status_col] == '' or row[status_col] == 'Ок':
                    groups[row[self._group_column(row)]].append(row)
                    counter += 1
            self.stdout.write('Read {} valid rows from the input file'.format(counter))

        Declaration.init()  # Apparently this is required to init mappings
        declarations = map(self.merge_group, groups.values())
        counter = 0
        for declaration in declarations:
            mapped = self.map_fields(declaration, id_prefix)

            res = Declaration.search().filter(
                Term(general__last_name=mapped[
                    'general']['last_name'].lower().split('-')) &
                Term(general__name=mapped[
                    'general']['name'].lower().split('-')) &
                Term(intro__declaration_year=mapped[
                    'intro']['declaration_year'])
            )

            if mapped['general']['patronymic']:
                res = res.filter(Term(general__patronymic=mapped[
                    'general']['patronymic'].lower()))

            res = res.execute()

            if res.hits:
                self.stdout.write(
                    "%s (%s) already exists" % (
                        mapped['general']['full_name'],
                        mapped['intro']['declaration_year']))

                mapped['_id'] = res.hits[0]._id

            item = Declaration(**mapped)
            item.save()
            counter += 1
        self.stdout.write('Loaded {} items to persistence storage'.format(counter))
开发者ID:poremchuk,项目名称:declarations.com.ua,代码行数:54,代码来源:loadvulyk.py

示例3: handle

# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import init [as 别名]
    def handle(self, *args, **options):
        try:
            file_path = args[0]
            id_prefix = args[1]
        except IndexError:
            raise CommandError("First argument must be a source file and second is a id prefix")

        groups = defaultdict(list)
        with open(file_path, "r", newline="", encoding="utf-8") as source:
            reader = csv.DictReader(source, delimiter=",")
            counter = 0
            for row in reader:
                status_col = "Status" if "Status" in row else "Статус"
                if row[status_col] == "" or row[status_col] == "Ок":
                    groups[row[self._group_column(row)]].append(row)
                    counter += 1
            self.stdout.write("Read {} valid rows from the input file".format(counter))

        Declaration.init()  # Apparently this is required to init mappings
        declarations = map(self.merge_group, groups.values())
        counter = 0
        for declaration in declarations:
            mapped = self.map_fields(declaration, id_prefix)

            res = Declaration.search().filter(
                Terms(general__last_name=mapped["general"]["last_name"].lower().split("-"))
                & Terms(general__name=mapped["general"]["name"].lower().split("-"))
                & Term(intro__declaration_year=mapped["intro"]["declaration_year"])
            )

            if mapped["general"]["patronymic"]:
                res = res.filter(Term(general__patronymic=mapped["general"]["patronymic"].lower()))

            res = res.execute()

            if res.hits:
                self.stdout.write(
                    "%s (%s) already exists" % (mapped["general"]["full_name"], mapped["intro"]["declaration_year"])
                )

                mapped["_id"] = res.hits[0]._id
            else:
                self.stdout.write(
                    "%s (%s) created" % (mapped["general"]["full_name"], mapped["intro"]["declaration_year"])
                )

            item = Declaration(**mapped)
            item.save()
            counter += 1
        self.stdout.write("Loaded {} items to persistence storage".format(counter))
开发者ID:talaveol,项目名称:declarations.com.ua,代码行数:52,代码来源:loadvulyk.py

示例4: handle

# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import init [as 别名]
    def handle(self, *args, **options):
        try:
            file_path = args[0]
        except IndexError:
            raise CommandError('First argument must be a source file')

        with open(file_path, 'r', newline='', encoding='utf-8') as source:
            reader = csv.DictReader(source, delimiter=";")
            counter = 0
            Declaration.init()  # Apparently this is required to init mappings
            for row in reader:
                item = Declaration(**self.map_fields(row))
                item.save()
                counter += 1
            self.stdout.write(
                'Loaded {} items to persistence storage'.format(counter))
开发者ID:gorysko,项目名称:declarations.com.ua,代码行数:18,代码来源:loadcatalog.py

示例5: handle

# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import init [as 别名]
    def handle(self, *args, **options):
        try:
            file_path = args[0]
        except IndexError:
            raise CommandError('First argument must be a source file')

        with open(file_path, 'r', newline='', encoding='utf-8') as source:
            reader = csv.DictReader(source, delimiter=";")
            counter = 0
            Declaration.init()  # Apparently this is required to init mappings
            for row in reader:
                mapped = self.map_fields(row)

                res = Declaration.search().filter(
                    Term(general__last_name=mapped[
                        "general"]["last_name"].lower().split("-")) &
                    Term(general__name=mapped[
                        "general"]["name"].lower().split("-")) &
                    Term(intro__declaration_year=mapped[
                        "intro"]["declaration_year"])
                )

                if mapped["general"]["patronymic"]:
                    res = res.filter(Term(general__patronymic=mapped[
                        "general"]["patronymic"].lower()))

                res = res.execute()

                if res.hits:
                    mapped["id"] = res.hits[0]._id

                item = Declaration(**mapped)
                item.save()
                counter += 1
            self.stdout.write(
                'Loaded {} items to persistence storage'.format(counter))
开发者ID:Amice13,项目名称:declarations.com.ua,代码行数:38,代码来源:loadcatalog.py


注:本文中的catalog.elastic_models.Declaration.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。