示例#1
0
def request(query={}):
    ssl._create_default_https_context = ssl._create_unverified_context
    response, content = OmekaClient(endpoint, apikey).get(resource, None, query)
    if response.status != 200:
        print(response.status, response.reason)
        exit()
    else:
        print(response.status, response.reason)
        return response, content
示例#2
0
def request(query={}):
    response, content = OmekaClient(endpoint,
                                    apikey).get(resource, None, query)
    if response.status != 200:
        print response.status, response.reason
        exit()
    else:
        print response.status, response.reason
        return response, content
示例#3
0
 def request(query={}):
     try:
         response, content = OmekaClient(endpoint, apikey).get(resource, None, query)
         if response.status != 200:
             print response.status, response.reason
             exit()
         else:
             return response, content
     except ServerNotFoundError:
         print 'The server was not found. Please check your endpoint and try again.'
         exit()
示例#4
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:
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)
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)
示例#7
0
    'Item type to use if there is no dcterms:type in the input row (Defaults to Text).'
)
parser.add_argument(
    '-n',
    '--in_collection',
    default="None",
    help=
    'Collection to use if there is no dcterms:type in the input row (Defaults to None).'
)
args = vars(parser.parse_args())

if not args['api_url'] or not args['key']:
    config = get_omeka_config()

endpoint = args['api_url'] if args['api_url'] else config['api_url']
apikey = args['key'] if args['api_url'] else config['key']

omeka_client = OmekaClient(endpoint.encode("utf-8"), logger, apikey)
inputfile = args['inputfile']
data_dir = args['download_cache']

# Because we can't efficiently query omeka via API, need to cache data about
# what gets uploaded and what ID it gets
shelf_file = "%s_item_cache" % endpoint.replace("/", "_").replace(":", ".")
shelf = shelve.open(shelf_file)

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

load(shelf)
示例#8
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"""
示例#9
0
#!/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
from omekaclient import OmekaClient
from omekautils import get_omeka_config
from omekautils import create_stream_logger
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)
for to_delete in ["items", "collections"]:
    logger.info('Deleting all %s', to_delete)
    resp, cont = omeka_client.get(to_delete)
    items = json.loads(cont)
    for item in items:
        logger.info('Deleting %s: %s', to_delete, item['id'])
        omeka_client.delete(to_delete, item['id'])
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']):
element_texts = []
for key in data:
    element_text = {"html": True, "text": "none", "element_set": {"id": 0}}
    element = {"id": d[key]}
    element_text["element"] = element
    text = str(data[key])
    if text.startswith(args["mdmark"]):
        element_text["text"] = markdown.markdown(text[len(args["mdmark"]):])
    else:
        element_text["text"] = text
    element_texts.append(element_text)
jsonobj["element_texts"] = element_texts

# Dump json object into a string and post, printing API response
jsonstr = json.dumps(jsonobj)
response, content = OmekaClient(endpoint, apikey).post("items", jsonstr)
location = response["location"]
print response.reason, location

# Optionally, upload and attach file to new item
if args["upload"] is not None:
    print "Uploading file ..."
    uploadjson = {"item": {"id": int(location.split("/")[-1])}}
    uploadmeta = json.dumps(uploadjson)
    uploadfile = open(args["upload"], "r").read()
    response, content = OmekaClient(endpoint,
                                    apikey).post_file(uploadmeta,
                                                      args["upload"],
                                                      uploadfile)
    print response.reason, response["location"]
示例#13
0
                    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']):
示例#14
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":