本文整理汇总了Python中catalog.elastic_models.Declaration.save方法的典型用法代码示例。如果您正苦于以下问题:Python Declaration.save方法的具体用法?Python Declaration.save怎么用?Python Declaration.save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类catalog.elastic_models.Declaration
的用法示例。
在下文中一共展示了Declaration.save方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import save [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))
示例2: handle
# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import save [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))
示例3: handle
# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import save [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))
示例4: handle
# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import save [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))
示例5: handle
# 需要导入模块: from catalog.elastic_models import Declaration [as 别名]
# 或者: from catalog.elastic_models.Declaration import save [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))