コード例 #1
0
import re
import os.path
"""Uploads a directory tree of photos to Omeka"""

# Define and parse command-line arguments
parser = argparse.ArgumentParser()
parser.add_argument('dir', default ='.', help='Directory to upload')
parser.add_argument('-k', '--key', default=None, help='Omeka API Key')
parser.add_argument('-u', '--api_url',default=None, help='Omeka API Endpoint URL (hint, ends in /api)')
parser.add_argument('-p', '--public', action='store_true', help='Make items public')
args = vars(parser.parse_args())
extensions =['.jpg','.jpeg','.png']
config = get_omeka_config()
endpoint = args['api_url'] if args['api_url'] <> None else config['api_url']
apikey   = args['key'] if args['api_url'] <> None else config['key']
omeka_client = OmekaClient(endpoint.encode("utf-8"), apikey)
file_stash = re.sub(":|/","_",endpoint) + ".json"

print file_stash;

if os.path.exists(file_stash):
    id_map = json.load(open(file_stash))
else:
    id_map = {}

dir = args['dir']

exif_id = omeka_client.getSetId("EXIF", create=True)
dc_id = omeka_client.getSetId("Dublin Core")
title_id = omeka_client.getElementId(dc_id, "Title")
collection_id = omeka_client.getCollectionId("Photos", create=True)
コード例 #2
0
parser.add_argument('-k', '--key', default=None, help='Omeka API Key')
parser.add_argument('-u', '--api_url',default=None, help='Omeka API Endpoint URL (hint, ends in /api)')
parser.add_argument('-i', '--identifier', default="Identifier", help='Name of an Identifier column in the input spreadsheet. ')
parser.add_argument('-d', '--download_cache', default="./data", help='Path to a directory in which to chache dowloads (defaults to ./data)')
parser.add_argument('-p', '--public', action='store_true', help='Make items public')
parser.add_argument('-c', '--create_collections', action='store_true', help='Auto-create missing collections')
parser.add_argument('-e', '--create_elements', action='store_true', help='Auto-create missing element types')
parser.add_argument('-y', '--create_item_types', action='store_true', help='Auto-create missing Item Types')
parser.add_argument('-q', '--quietly', action='store_true', help='Only log errors and warnings not the constant stream of info')
args = vars(parser.parse_args())


config = get_omeka_config()
endpoint = args['api_url'] if args['api_url'] <> None else config['api_url']
apikey   = args['key'] if args['api_url'] <> None else config['key']
omeka_client = OmekaClient(endpoint.encode("utf-8"), logger, apikey)
inputfile = args['inputfile']
identifier_column = args['identifier']
data_dir = args['download_cache']

if args["quietly"]:
    logger.setLevel(30)

csv_data = CSVData(inputfile)
csv_data.get_items()

for collection in csv_data.collections:
    id = collection.id
    title = collection.title
    print id
    if id != None:
コード例 #3
0
from sys import stdout
import argparse
import json

logger = create_stream_logger('deleting', stdout)


config = get_omeka_config()
parser = argparse.ArgumentParser()
parser.add_argument('-k', '--key', default=None, help='Omeka API Key')
parser.add_argument('-u', '--api_url',default=None, help='Omeka API Endpoint URL (hint, ends in /api)')
args = vars(parser.parse_args())

endpoint = args['api_url'] if args['api_url'] <> None else config['api_url']
apikey   = args['key'] if args['api_url'] <> None else config['key']
omeka_client = OmekaClient(endpoint.encode("utf-8"), logger, apikey)
deleted = {}
for to_delete in ["items", "collections"]:
    logger.info('Deleting all %s', to_delete)
    resp, cont = omeka_client.get(to_delete)
    items = json.loads(cont)
    count = 0
    for item in items:
        logger.info('Deleting %s: %s', to_delete, item['id'])
        omeka_client.delete(to_delete, item['id'])
        count += 1
    deleted[to_delete] = count

for d in deleted:
    logger.info('Deleted %d %s', deleted[d], d)
コード例 #4
0
parser.add_argument('-i', '--identifier', default="Identifier", help='Name of an Identifier column in the input spreadsheet. ')
parser.add_argument('-d', '--download_cache', default="./data", help='Path to a directory in which to chache dowloads (defaults to ./data)')
parser.add_argument('-t', '--title', default="Title", help='Name of a Title column in the input spreadsheet. ')
parser.add_argument('-p', '--public', action='store_true', help='Make items public')
parser.add_argument('-f', '--featured', action='store_true', help='Make items featured')
parser.add_argument('-c', '--create_collections', action='store_true', help='Auto-create missing collections')
parser.add_argument('-e', '--create_elements', action='store_true', help='Auto-create missing element types')
parser.add_argument('-y', '--create_item_types', action='store_true', help='Auto-create missing Item Types')
parser.add_argument('-q', '--quietly', action='store_true', help='Only log errors and warnings not the constant stream of info')
args = vars(parser.parse_args())


config = get_omeka_config()
endpoint = args['api_url'] if args['api_url'] <> None else config['api_url']
apikey   = args['key'] if args['api_url'] <> None else config['key']
omeka_client = OmekaClient(endpoint.encode("utf-8"), logger, apikey)
inputfile = args['inputfile']
identifier_column = args['identifier']
title_column = args['title']
data_dir = args['download_cache']
if args["quietly"]:
    logger.setLevel(30)


#Auto-map to elements from these sets
#TODO make the 'bespoke' one configurable
default_element_set_names = ['Dublin Core','Item Type Metadata', 'Bespoke Metadata']


def download_and_upload_files(new_item_id, original_id, URLs, files):
    """Handle any dowloads, cache as files, then upload all files"""
コード例 #5
0
ファイル: test.py プロジェクト: bdunnette/omeka-client-py
#!/usr/bin/python

from omekaclient import OmekaClient

client = OmekaClient("http://localhost/omeka/api", "fd11f6fdcdcd2f524555b089790824ede6d27cff")

# GET /items/:id
response, content = client.get("items", id=1)

# GET /items
#response, content = client.get("items")

# POST /items
#response, content = client.post("items", data='{"public":true}')

# PUT /items/:id
#response, content = client.put("items", 1, data='{"public":false}')

# DELETE /items/:id
#response, content = client.delete("items", 1)

print response, content
コード例 #6
0
logger = create_stream_logger('converting', stdout)


config = get_omeka_config()
parser = argparse.ArgumentParser()
parser.add_argument('-k', '--key', default=None, help='Omeka API Key')
parser.add_argument('-u', '--api_url', default=None, help='Omeka API Endpoint URL (hint, ends in /api)')
parser.add_argument('-d', '--delete_html', action='store_true', help='Delete html docs')
parser.add_argument('-n', '--do_not_convert', action='store_true', help='Do not convert')

args = vars(parser.parse_args())

endpoint = args['api_url'] if args['api_url'] <> None else config['api_url']
apikey   = args['key'] if args['api_url'] <> None else config['key']
omeka_client = OmekaClient(endpoint.encode("utf-8"), logger, apikey)

resp, cont = omeka_client.get("items")
items = json.loads(cont)
temp_dir = tempfile.mkdtemp()
os.chmod(temp_dir, 0o2770) #Sets group permissions and "sticky bit"

num_docs_found = 0
num_html_uploaded = 0
num_html_deleted = 0
for item in items:
    logger.info('Looking at %s', item['id'])
  
    #First pass - delete HTML if required
    if args['delete_html']:
        for f in omeka_client.get_files_for_item(item['id']):
コード例 #7
0
#!/usr/bin/env python3

import json
from omekaclient import OmekaClient
import os

dirBase = "/Users/jonathan/Desktop/MN/compressed/"
subDirSemantics = ("Year", 3, 52)
subDirMapping = {1906: 2, 1907: 3, 1908: 4, 1909: 5}

client = OmekaClient("http://www.indiana.edu/~srifias/omeka/api", "6daa92a0ebce6605f7eba1cbdb0ee7e3051cfbb7")



def newItem(fullPath, thisDir, filename):
	global subDirSemantics
	global subDirMapping
	global client

	ALLDATA = {
		"item_type":
		{
			"html":False,
			"id": 18                             # the item type ID
		},
		"collection":
		{
			"html":False,
			"id": subDirMapping[subDir]          # the collection ID
		},
		"element_texts":