Last active
February 21, 2016 02:21
-
-
Save mrhanlon/9ea30dabf39bec59e8ff to your computer and use it in GitHub Desktop.
Quick script to index metadata from Agave in ElasticSearch
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/python | |
import sys | |
import requests | |
import json | |
from agavepy.agave import Agave | |
from django.contrib.auth import get_user_model | |
def index_metadata(username): | |
me = get_user_model().objects.get(username='') | |
me.agave_oauth.refresh() | |
ag = Agave(api_server='https://agave.designsafe-ci.org/', | |
token=me.agave_oauth.access_token) | |
limit = 100 | |
offset = 0 | |
query = json.dumps({'name': 'object'}) | |
data = ag.meta.listMetadata(q=query, limit=limit, offset=offset) | |
while len(data) > 0: | |
for d in data: | |
print 'Indexing %s...' % (d['uuid']) | |
requests.put( | |
'http://designsafe-es01.tacc.utexas.edu:9200/designsafe/objects/%s' % d['uuid'], | |
json.dumps(d)) | |
offset = offset + limit | |
data = ag.meta.listMetadata(q=query, limit=limit, offset=offset) | |
if __name__ == '__main__': | |
if len(sys.argv) == 2: | |
username = sys.argv[1] | |
index_metadata(username) | |
else: | |
print '''Usage: python index_meta.py <username>, where <username> is the username | |
of the user to index metadata for.''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment