Skip to content

Instantly share code, notes, and snippets.

@seanupton
Created February 7, 2019 23:50
Show Gist options
  • Save seanupton/aab58b96df3c6f0a02d07c221b57b4a2 to your computer and use it in GitHub Desktop.
Save seanupton/aab58b96df3c6f0a02d07c221b57b4a2 to your computer and use it in GitHub Desktop.
Hypothetical (untested) example ingesting an NDNP Issue and its pages, along with associated files and metadata
require 'newspaper_works_fixtures'
def ndnp_ingest_page(issue, page_data):
page = NewspaperPage.new
page.title = ["Page #{page_data.metadata.page_number}"]
page.height = page_data.metadata.height
page.width = page_data.metadata.width
page.save!
work_files = NewspaperWorks::Data::WorkFiles.new(page)
page.files.each do |path|
ext = path.downcase.split('.')[-1]
if ['tif', 'tiff'].include?(ext)
work_files.assign(path)
else
work_files.derivatives.assign(path)
end
end
work_files.commit!
def ndnp_ingest_issue(publication, path):
data = NewspaperWorks::Ingest::NDNP::IssueIngest.new(path)
issue = NewspaperIssue.create
issue.title = [data.metadata.issue]
issue.save!
publication.members << issue
publication.lccn ||= data.metadata.lccn
publication.save!
issue.each { |page| ndnp_ingest_page(issue, page)}
issuexml = File.join(
NewspaperWorksFixtures.file_fixtures,
'ndnp/batch_local/sn85058233/17082901001/1935080201/1935080201.xml'
)
publication = NewspaperTitle.new
publication.title = ['Strange Times']
publication.save!
ndnp_ingest_issue(publication, issuexml)
issue.metadata.lccn
issue.each { |page| puts [page.metadata.page_number, page.files] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment