首页 > 解决方案 > 在 CKAN 中获取包的 HarvestSource

问题描述

根据数据集包的 id,我如何确定包是否被收割、由哪个收割机以及该收割机的基本 URL 是什么?

类似于以下内容:

guid = '65715c6e-bbaf-3def-982b-3b5156272da7'
harvest_source = getHarvestSource(guid)

if (harvest_source):
  type = harvest_source.type() # whatever was set as the name attribute for this harvester class
  base_url = harvest_source.url() # whatever was set as the URL in the admin interface

标签: ckan

解决方案


我还没有尝试过,但是通过阅读模型,我期望得到这样的结果:

from ckan.model import Package

id = u'65715c6e-bbaf-3def-982b-3b5156272da7'
dataset = model.Package.get(id)
dataset_was_harvested = bool(len(dataset.harvest_objects) > 0)
if dataset_was_harvested:
    ho = dataset.harvest_objects[0]  # there's not usually more than 1
    source = ho.source  # i.e. the harvest source is "the harvester"
    source.url  # i.e. the harvester's base url
    source.type # is also useful

推荐阅读