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
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
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()
'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)
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"]