在 CKAN 中获取包的 HarvestSource

Get HarvestSource for a package in CKAN

根据数据集包的 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

我还没有尝试过,但是通过阅读 model 我希望是这样的:

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