Created
July 31, 2012 20:00
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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