url = "https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=atom&language=en" fh = urllib.urlopen(url) data = fh.read() fh.close() nss = {'atom': 'http://www.w3.org/2005/Atom'} dom = etree.XML(data) subs = dom.xpath('//atom:summary[@type="html"]/text()', namespaces=nss) fac = ManifestFactory() fac.set_base_metadata_uri("http://iiif-dev.localhost/prezi/mw/") fac.set_base_image_uri("http://dlss-dev-azaroth.stanford.edu/services/iiif/") fac.set_base_metadata_dir("/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/mw") fac.set_iiif_image_info(2.0, 2) fac.set_debug("error") # warn will warn for recommendations, by default label = "Wikimedia Pictures of the Day" mf = fac.manifest(ident="manifest", label=label) mf.viewingHint = "individuals" seq = mf.sequence(ident="normal", label="Normal Order") c = 0 for s in subs: hdom = etree.HTML(s) title = hdom.xpath('//span')[0] title = etree.tostring(title)
import urllib import json from factory import ManifestFactory baseq = "http://www.vam.ac.uk/api/json/museumobject/search?images=1&" baseo = "http://www.vam.ac.uk/api/json/museumobject/" # + O 123456 baseimg = "http://media.vam.ac.uk/media/thira/collection_images/" # + pid[:6] + / + pid .jpg destdir = "/path/to/images/vam" fac = ManifestFactory() fac.set_base_image_uri("http://localhost/iiif") fac.set_iiif_image_info(version="2.0") basemd = "http://localhost/prezi/vam/" basedir = "/path/to/htdocs/prezi/vam/" fac.set_base_metadata_uri(basemd) fac.set_base_metadata_dir(basedir) # before=date&after=date&q=term # offset=n q1 = baseq + "before=1200&after=1100&q=manuscript" # 126 objects def fetch(q, offset=0): if offset: q += "&offset=%s" % offset fh = urllib.urlopen(q) data = fh.read() fh.close() js = json.loads(data)
# BL Flickr TSV + JSON to IIIF Metadata # Data available here: https://github.com/BL-Labs/imagedirectory import sys, os, re import glob import ljson from factory import ManifestFactory fac = ManifestFactory() fac.set_base_metadata_uri("https://github.com/BL-Labs/imagedirectory/iiif") fac.set_base_metadata_dir('/Users/azaroth/Development/bl/imagedirectory/iiif') fh = file('book_metadata.json') data = fh.read() fh.close() books = ljson.loads(data) # volume / Publisher / Title / Author / ? / pub place / book id / book ARK / flickr_url / # image_idx / page / flickr_id / f_small / f_s_height / f_s_width / medium / large / original # Can be images from the same book in multiple TSV files, as based on image size so build in parallel and sort manifests = {} files = glob.glob("*.tsv") files.sort() for f in files: fh = file(f) data = fh.read() fh.close() lines = data.split('\r\n')
# -*- coding: utf-8 -*- from factory import ManifestFactory from lxml import etree import os fh = file('web-view.html') html = fh.read() fh.close() dom = etree.HTML(html) subs = dom.xpath('//div[@class="related-records"]/dl[@class="return-art"]') fac = ManifestFactory() fac.set_base_metadata_uri("http://vm-imgrepo-tdp.nga.gov/public/manifests/") fac.set_base_image_uri("http://vm-imgrepo-tdp.nga.gov/public/objects/") fac.set_base_metadata_dir("/mnt/images/public/manifests") fac.set_iiif_image_info(2.0, 2) fac.set_debug("error") # warn will warn for recommendations, by default label = "Cézanne Sketchbook" mdhash = {"Dates": "c. 1877/1900", "Creator": "Cézanne, Paul (1839-1906)"} mdhash["Inscription"] = "Various notations overall" mdhash["Provenance"] = """ <div>Paul Cézanne (the artist's son), Paris; <br/>Paul Guillaume, Paris; <br/>Adrien Chappuis, Tresserve, Switzerland, 1933; <br/>Paul Mellon, Upperville, VA, 1967; <br/>gift to NGA, 1991 </div>""" mdhash["Exhibition History"] = """<div>
def do_record(rec, rx, host, s, cxn, sequence, lastrec): deleted = rec.xpath('./o:header/@status', namespaces=ALLNS) if deleted: return format = rec.xpath('./o:metadata/odc:dc/dc:format/text()', namespaces=ALLNS) # Strip out non images skip = 0 for f in format: if f.find('/') > -1 and (not f.startswith('image/') or f.endswith('/pdf')): skip = 1 break if skip: return # request info to see if we're compound object (cpd) # if we are, then work backwards from current ID to find records for individual pages # Then reverse the order and call it a Manifest :) identifier = rec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] idx = int(identifier[identifier.rfind('/')+1:]) ajaxinfo = get_json('http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, idx)) try: if not ajaxinfo['imageinfo'].has_key('type'): return except: print 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, idx) print ajaxinfo raise if ajaxinfo['imageinfo']['type'] == 'cpd': # Compound Object to process separately # Walk backwards through images until hit previous entry in OAI list # make a folder... print "--- Compound Object: %s" % idx sys.stdout.flush() if os.path.exists('%s/%s/manifest.json' % (s,idx)): return try: os.mkdir("%s/%s" % (s, idx)) except: pass os.chdir("%s/%s" % (s, idx)) if rx == 0: # Need to check last record of previous chunk if lastrec: previd = lastrec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/')+1:])+1 else: start_image = 1 else: prev = recs[rx-1] previd = prev.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/')+1:])+1 pages = [] for imgid in range(start_image, idx): pinfo = {'id': imgid} # get H/W from ajax iajax = get_json('http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, imgid)) if not iajax['imageinfo'].has_key('height'): continue pinfo['h'] = iajax['imageinfo']['height'] pinfo['w'] = iajax['imageinfo']['width'] if (int(pinfo['h']) == 0 or int(pinfo['w']) == 0): continue try: pinfo['title'] = iajax['imageinfo']['title']['0'] except: pinfo['title'] = "Image %s" % imgid cxn.put("%s::%s::%s" % (host, s, imgid), "%s,%s" % (pinfo['w'], pinfo['h'])) pages.append(pinfo) if not pages: # back to host directory os.chdir('../..') return title = rec.xpath('./o:metadata/odc:dc/dc:title/text()', namespaces=ALLNS) creator = rec.xpath('./o:metadata/odc:dc/dc:creator/text()', namespaces=ALLNS) date = rec.xpath('./o:metadata/odc:dc/dc:date/text()', namespaces=ALLNS) description = rec.xpath('./o:metadata/odc:dc/dc:description/text()', namespaces=ALLNS) language = rec.xpath('./o:metadata/odc:dc/dc:language/text()', namespaces=ALLNS) # reinstantiate factory for subdir. not great but ... cfac = ManifestFactory() cfac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/%s/" % (host, s, idx)) cfac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) cfac.set_base_metadata_dir(os.getcwd()) cfac.set_iiif_image_info("2.0", "1") fac.set_debug('error') cmanifest = cfac.manifest(label=title[0]) try: cmanifest.set_metadata({"Creator": creator[0]}) except: pass try: cmanifest.set_metadata({"Date": date[0]}) except: pass try: cmanifest.set_metadata({"Language": language[0]}) except: pass try: cmanifest.description = description[0] except: pass cmanifest.viewingHint = "paged" cseq = cmanifest.sequence() for p in pages: cvs = cseq.canvas(ident="p%s" % p['id'], label=p['title']) cvs.set_hw(int(p['h']), int(p['w'])) anno = cvs.annotation() img = anno.image(str(p['id']), iiif=True) img.height = p['h'] img.width = p['w'] try: cmanifest.toFile(compact=False) except: print "FAILED TO WRITE %s/%s/manifest.json" % (s, idx) # back to host directory os.chdir('../..') else: # We're just a collection of images h = ajaxinfo['imageinfo']['height'] w = ajaxinfo['imageinfo']['width'] if int(h) == 0 or int(w) == 0: return ttl = ajaxinfo['imageinfo']['title']['0'] cxn.put("%s::%s::%s" % (host, s, idx), "%s,%s" % (w, h)) cvs = sequence.canvas(ident="p%s" % idx, label=ttl) cvs.set_hw(int(h), int(w)) anno = cvs.annotation() img = anno.image(str(idx), iiif=True) img.height = h img.width = w
"nlw":"http://dev.llgc.org.uk/digitisation/identifiers/", "oai":"http://www.openarchives.org/OAI/2.0/", "rdf":"http://www.w3.org/1999/02/22-rdf-syntax-ns#", "oai_dc":"http://www.openarchives.org/OAI/2.0/oai_dc/", "xsi":"http://www.w3.org/2001/XMLSchema-instance", "mix":"http://www.loc.gov/mix/v20", "xlink":"http://www.w3.org/1999/xlink", "mods":"http://www.loc.gov/mods/v3", "rights":"http://cosimo.stanford.edu/sdr/metsrights/"} from factory import ManifestFactory fac = ManifestFactory() fac.set_base_image_uri("http://dams.llgc.org.uk/iiif/image/") fac.set_iiif_image_info(version="1.1", lvl="1") fac.set_base_metadata_dir('/path/to/data') fac.set_base_metadata_uri("http://showcase.iiif.io/shims/wales/potter/") fac.set_debug('error') def xpath(dom, path): return dom.xpath(path, namespaces=namespaces) def fetch(url, type="XML", retry=0): # Don't cache here, only the results fh = urllib.urlopen(url) data = fh.read() fh.close() if type == "XML": try:
url = "https://commons.wikimedia.org/w/api.php?action=featuredfeed&feed=potd&feedformat=atom&language=en" fh = urllib.urlopen(url) data = fh.read() fh.close() nss = {"atom": "http://www.w3.org/2005/Atom"} dom = etree.XML(data) subs = dom.xpath('//atom:summary[@type="html"]/text()', namespaces=nss) fac = ManifestFactory() fac.set_base_metadata_uri("http://iiif-dev.localhost/prezi/mw/") fac.set_base_image_uri("http://dlss-dev-azaroth.stanford.edu/services/iiif/") fac.set_base_metadata_dir("/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/mw") fac.set_iiif_image_info(2.0, 2) fac.set_debug("error") # warn will warn for recommendations, by default label = "Wikimedia Pictures of the Day" mf = fac.manifest(ident="manifest", label=label) mf.viewingHint = "individuals" seq = mf.sequence(ident="normal", label="Normal Order") c = 0 for s in subs: hdom = etree.HTML(s) title = hdom.xpath("//span")[0]
from bottle import Bottle, route, run, request, response, abort, error import os, sys import factory from lxml import etree import uuid import urllib, urllib2, urlparse from factory import ManifestFactory fac = ManifestFactory() fac.set_base_image_uri("http://iiif-dev.localhost/services/chronam/") fac.set_iiif_image_info(version="2.0", lvl="1") fac.set_base_metadata_dir( '/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/chronam/') fac.set_base_metadata_uri("http://localhost:8080/") # http://localhost:8080/list/lccn/sn99021999/1915-03-27/ed-1/seq-1.json fac.set_debug('error') PFX = "" INFO_CACHE = {} CACHEDIR = '/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/chronam/' class ChronAmManifestShim(object): def __init__(self): pass def fetch(self, url, format="json"):
for (k, v) in queries.items(): thing[k] = [] q2 = qt % (k, uri, v) sparql.setQuery(q2) results2 = sparql.query().convert() for r2 in results2["results"]["bindings"]: thing[k].append(r2[k]["value"]) # And now make the Manifest objid = os.path.split(uri)[-1] try: os.mkdir(basedir + "/" + objid) except: pass # already exists fac.set_base_metadata_uri(basemd + objid) fac.set_base_metadata_dir(basedir + "/" + objid) mfst = fac.manifest() # Most British Museum objects don't have titles lbl = thing.get("title") # Maybe there's some with more than one? if len(lbl) > 1: mfst.label = lbl elif len(lbl): mfst.label = lbl[0] else: mfst.label = thing.get("typeLabel", [""])[0] desc = thing.get("desc") if len(desc) > 1: desc.sort(key=lambda x: len(x), reverse=True)
from bottle import Bottle, route, run, request, response, abort, error import os, sys import factory from lxml import etree import uuid import urllib, urllib2, urlparse from factory import ManifestFactory fac = ManifestFactory() fac.set_base_image_uri("http://showcase.iiif.io/shims/veridian/image") fac.set_iiif_image_info(version="2.0", lvl="1") fac.set_base_metadata_dir('/tmp/') fac.set_base_metadata_uri("http://showcase.iiif.io/shims/veridian/prezi/") fac.set_debug('error') PFX = "" INFO_CACHE = {} CACHEDIR = '/tmp/' VSERVER = "http://cdnc.ucr.edu/cgi-bin/cdnc" class ManifestShim(object): def __init__(self): pass def fetch(self, url, format="json"):
def do_record(rec, rx, host, s, cxn, sequence, lastrec): deleted = rec.xpath('./o:header/@status', namespaces=ALLNS) if deleted: return format = rec.xpath('./o:metadata/odc:dc/dc:format/text()', namespaces=ALLNS) # Strip out non images skip = 0 for f in format: if f.find('/') > -1 and (not f.startswith('image/') or f.endswith('/pdf')): skip = 1 break if skip: return # request info to see if we're compound object (cpd) # if we are, then work backwards from current ID to find records for individual pages # Then reverse the order and call it a Manifest :) identifier = rec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] idx = int(identifier[identifier.rfind('/') + 1:]) ajaxinfo = get_json( 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, idx)) try: if not ajaxinfo['imageinfo'].has_key('type'): return except: print 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % ( host, s, idx) print ajaxinfo raise if ajaxinfo['imageinfo']['type'] == 'cpd': # Compound Object to process separately # Walk backwards through images until hit previous entry in OAI list # make a folder... print "--- Compound Object: %s" % idx sys.stdout.flush() if os.path.exists('%s/%s/manifest.json' % (s, idx)): return try: os.mkdir("%s/%s" % (s, idx)) except: pass os.chdir("%s/%s" % (s, idx)) if rx == 0: # Need to check last record of previous chunk if lastrec: previd = lastrec.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/') + 1:]) + 1 else: start_image = 1 else: prev = recs[rx - 1] previd = prev.xpath('./o:header/o:identifier/text()', namespaces=ALLNS)[0] start_image = int(previd[previd.rfind('/') + 1:]) + 1 pages = [] for imgid in range(start_image, idx): pinfo = {'id': imgid} # get H/W from ajax iajax = get_json( 'http://%s/utils/ajaxhelper/?action=1&CISOROOT=%s&CISOPTR=%s' % (host, s, imgid)) if not iajax['imageinfo'].has_key('height'): continue pinfo['h'] = iajax['imageinfo']['height'] pinfo['w'] = iajax['imageinfo']['width'] if (int(pinfo['h']) == 0 or int(pinfo['w']) == 0): continue try: pinfo['title'] = iajax['imageinfo']['title']['0'] except: pinfo['title'] = "Image %s" % imgid cxn.put("%s::%s::%s" % (host, s, imgid), "%s,%s" % (pinfo['w'], pinfo['h'])) pages.append(pinfo) if not pages: # back to host directory os.chdir('../..') return title = rec.xpath('./o:metadata/odc:dc/dc:title/text()', namespaces=ALLNS) creator = rec.xpath('./o:metadata/odc:dc/dc:creator/text()', namespaces=ALLNS) date = rec.xpath('./o:metadata/odc:dc/dc:date/text()', namespaces=ALLNS) description = rec.xpath('./o:metadata/odc:dc/dc:description/text()', namespaces=ALLNS) language = rec.xpath('./o:metadata/odc:dc/dc:language/text()', namespaces=ALLNS) # reinstantiate factory for subdir. not great but ... cfac = ManifestFactory() cfac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/%s/" % (host, s, idx)) cfac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) cfac.set_base_metadata_dir(os.getcwd()) cfac.set_iiif_image_info("2.0", "1") fac.set_debug('error') cmanifest = cfac.manifest(label=title[0]) try: cmanifest.set_metadata({"Creator": creator[0]}) except: pass try: cmanifest.set_metadata({"Date": date[0]}) except: pass try: cmanifest.set_metadata({"Language": language[0]}) except: pass try: cmanifest.description = description[0] except: pass cmanifest.viewingHint = "paged" cseq = cmanifest.sequence() for p in pages: cvs = cseq.canvas(ident="p%s" % p['id'], label=p['title']) cvs.set_hw(int(p['h']), int(p['w'])) anno = cvs.annotation() img = anno.image(str(p['id']), iiif=True) img.height = p['h'] img.width = p['w'] try: cmanifest.toFile(compact=False) except: print "FAILED TO WRITE %s/%s/manifest.json" % (s, idx) # back to host directory os.chdir('../..') else: # We're just a collection of images h = ajaxinfo['imageinfo']['height'] w = ajaxinfo['imageinfo']['width'] if int(h) == 0 or int(w) == 0: return ttl = ajaxinfo['imageinfo']['title']['0'] cxn.put("%s::%s::%s" % (host, s, idx), "%s,%s" % (w, h)) cvs = sequence.canvas(ident="p%s" % idx, label=ttl) cvs.set_hw(int(h), int(w)) anno = cvs.annotation() img = anno.image(str(idx), iiif=True) img.height = h img.width = w
if SETS_TO_DO and not s in SETS_TO_DO: print "skipping %s / %s" % (s, sinfo['name']) continue try: print "Processing Set: %s" % sinfo['name'] except: print "Processing Set: %s" % s sys.stdout.flush() if os.path.exists(s): continue os.mkdir(s) fac = ManifestFactory() fac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/" % (host, s)) fac.set_base_metadata_dir(os.path.join(os.getcwd(), s)) fac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) fac.set_iiif_image_info("2.0", "1") fac.set_debug('error') manifest = fac.manifest(label=sinfo['name']) if sinfo['desc']: manifest.description = str(sinfo['desc']) manifest.attribution = "Converted from http://%s/" % host manifest.viewingHint = "individuals" sequence = manifest.sequence() dom = get_xml( 'http://%s/oai/oai.php?verb=ListRecords&set=%s&metadataPrefix=oai_dc' % (host, s)) recs = dom.xpath('/o:OAI-PMH/o:ListRecords/o:record', namespaces=ALLNS)
imageUris = [BASEURL + "resources/page1-full.png", BASEURL + "resources/page2-full.png"] textUris = [BASEURL + "resources/page1.txt", BASEURL + "resources/page2.txt"] htmlUris = [BASEURL + "resources/page1.html", BASEURL + "resources/page2.html"] transcriptions = [ ["Top of First Page to Display", "Middle of First Page on Angle", "Bottom of First Page to Display"], ["Top of Second Page to Display", "Middle of Second Page on Angle", "Bottom of Second Page on Angle"] ] line1Dims = "225,70,750,150" # Configure the factory fac = ManifestFactory() fac.set_base_metadata_uri(BASEURL) fac.set_base_metadata_dir(HOMEDIR) fac.set_base_image_uri(IMAGE_BASEURL) fac.set_iiif_image_info(2.0, 1) fac.set_debug('error') testInfo = { # Done 1 : {"title": "Minimum Required Fields"}, 2 : {"title": "Metadata Pairs", 'mfprops': [('metadata',{'date': 'some date'})]}, 3 : {"title": "Metadata Pairs with Languages", 'mfprops': [('metadata', {'date': {'en':'some data','fr':'quelquetemps'}})]}, 4 : {"title": "Metadata Pairs with Multiple Values in same Language", 'mfprops':[('metadata',{'date': ['some date', 'some other date']})]}, 5 : {"title": "Description field", 'mfprops': [('description',"This is a description")]}, 6 : {"title": "Multiple Descriptions", 'mfprops': [('description',["This is one description", {"en":"This is another"}])]}, 7 : {"title": "Rights Metadata", 'mfprops': [('attribution', "Owning Institution"), ('license','http://creativecommons.org/licenses/by-nc/3.0/')]}, 8 : {"title": "SeeAlso link / Manifest", 'mfprops':[('seeAlso','http://www.example.org/link/to/metadata')]},
for (k, v) in queries.items(): thing[k] = [] q2 = qt % (k, uri, v) sparql.setQuery(q2) results2 = sparql.query().convert() for r2 in results2['results']['bindings']: thing[k].append(r2[k]['value']) # And now make the Manifest objid = os.path.split(uri)[-1] try: os.mkdir(basedir + '/' + objid) except: pass # already exists fac.set_base_metadata_uri(basemd + objid) fac.set_base_metadata_dir(basedir + '/' + objid) mfst = fac.manifest() # Most British Museum objects don't have titles lbl = thing.get('title') # Maybe there's some with more than one? if len(lbl) > 1: mfst.label = lbl elif len(lbl): mfst.label = lbl[0] else: mfst.label = thing.get('typeLabel', [''])[0] desc = thing.get('desc') if len(desc) > 1: desc.sort(key=lambda x: len(x), reverse=True)
from bottle import Bottle, route, run, request, response, abort, error import os, sys import factory from lxml import etree import uuid import urllib, urllib2, urlparse from factory import ManifestFactory fac = ManifestFactory() fac.set_base_image_uri("http://iiif-dev.localhost/services/chronam/") fac.set_iiif_image_info(version="2.0", lvl="1") fac.set_base_metadata_dir('/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/chronam/') fac.set_base_metadata_uri("http://localhost:8080/") # http://localhost:8080/list/lccn/sn99021999/1915-03-27/ed-1/seq-1.json fac.set_debug('error') PFX = "" INFO_CACHE = {} CACHEDIR = '/Users/azaroth/Dropbox/Rob/Web/iiif-dev/prezi/chronam/' class ChronAmManifestShim(object): def __init__(self): pass def fetch(self, url, format="json"):
transcriptions = [[ "Top of First Page to Display", "Middle of First Page on Angle", "Bottom of First Page to Display" ], [ "Top of Second Page to Display", "Middle of Second Page on Angle", "Bottom of Second Page on Angle" ]] line1Dims = "225,70,750,150" # Configure the factory fac = ManifestFactory() fac.set_base_metadata_uri(BASEURL) fac.set_base_metadata_dir(HOMEDIR) fac.set_base_image_uri(IMAGE_BASEURL) fac.set_iiif_image_info(2.0, 1) fac.set_debug('error') testInfo = { # Done 1: { "title": "Minimum Required Fields" }, 2: { "title": "Metadata Pairs", 'mfprops': [('metadata', { 'date': 'some date' })]
from factory import ManifestFactory import os # Example script to build a manifest out of all the images in a directory destdir = "/path/to/images" fac = ManifestFactory() fac.set_debug("error") fac.set_base_image_uri("http://localhost/iiif") fac.set_base_image_dir(destdir) fac.set_iiif_image_info() fac.set_base_metadata_uri("http://localhost/prezi/") fac.set_base_metadata_dir("/path/to/prezi/") mflbl = os.path.split(destdir)[1].replace("_", " ").title() mfst = fac.manifest(label=mflbl) seq = mfst.sequence() for fn in os.listdir(destdir): ident = fn[:-4] title = ident.replace("_", " ").title() cvs = seq.canvas(ident=ident, label=title) cvs.add_image_annotation(ident, True) mfst.toFile(compact=False)
from factory import ManifestFactory import urllib import os, sys baseq = "http://data.fitzmuseum.cam.ac.uk/api/?size=1000&query=" q = "Marlay%20AND%20cutting%20AND%20Category:illuminated*" destdir = "/path/to/images/fitzwilliam" fac = ManifestFactory() fac.set_base_image_uri("http://iiif-dev.localhost/services/2.0") fac.set_iiif_image_info(version="2.0") basemd = "http://localhost/prezi/fitz/" basedir = "/path/to/htdocs/prezi/fitz/" fac.set_base_metadata_uri(basemd) fac.set_base_metadata_dir(basedir) fh = urllib.urlopen(baseq+q) data = fh.read() fh.close() results = json.loads(data) mfst = fac.manifest(label="Marlay Cuttings") seq = mfst.sequence() for res in results['results']: if not res.has_key('image'): continue ident = res.get('identifier') name = res.get('Name') title = res.get('Title', name)
if SETS_TO_DO and not s in SETS_TO_DO: print "skipping %s / %s" % (s , sinfo['name']) continue try: print "Processing Set: %s" % sinfo['name'] except: print "Processing Set: %s" % s sys.stdout.flush() if os.path.exists(s): continue os.mkdir(s) fac = ManifestFactory() fac.set_base_metadata_uri(BASE_MD_URL + "/%s/%s/" % (host, s)) fac.set_base_metadata_dir(os.path.join(os.getcwd(), s)) fac.set_base_image_uri(BASE_IMG_URL + "/%s/%s/" % (host, s)) fac.set_iiif_image_info("2.0", "1") fac.set_debug('error') manifest = fac.manifest(label=sinfo['name']) if sinfo['desc']: manifest.description = str(sinfo['desc']) manifest.attribution = "Converted from http://%s/" % host manifest.viewingHint = "individuals" sequence = manifest.sequence() dom = get_xml('http://%s/oai/oai.php?verb=ListRecords&set=%s&metadataPrefix=oai_dc' % (host, s)) recs = dom.xpath('/o:OAI-PMH/o:ListRecords/o:record', namespaces=ALLNS) lastrec = None for rx in range(len(recs)):