Skip to content

Instantly share code, notes, and snippets.

@jjjake
Created July 31, 2012 20:00
Show Gist options
  • Save jjjake/3219990 to your computer and use it in GitHub Desktop.
Save jjjake/3219990 to your computer and use it in GitHub Desktop.
An example script used for editing metadata on archive.org that utilizes the Archive's new Metadata Write API, and the Python HTTP library, Requests.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import json
import requests
COOKIES = {'logged-in-sig': os.environ['LOGGED_IN_SIG'],
'logged-in-user': os.environ['LOGGED_IN_USER'],
}
def write_metadata(item, patch, target="metadata"):
params = json.dumps({"-patch": PATCH, "-target": target})
url = 'http://archive.org/metadata/%s' % item
r = requests.patch(url, params=params, cookies=COOKIES)
return r.text
ITEM='meta-test-item'
PATCH = {"replace": "/title", "value": "Metadata Write API Test Item",
"add": "/new-metadata-element", "value": "new metadata :: ∆ ∪†ƒ-∞ ∆"
}
print write_metadata(ITEM, PATCH)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment