Skip to content

Instantly share code, notes, and snippets.

@fabianvf
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabianvf/a1c77122d60556b70660 to your computer and use it in GitHub Desktop.
Save fabianvf/a1c77122d60556b70660 to your computer and use it in GitHub Desktop.
Graph data osf
# coding: utf-8
import json
import requests
HEADERS = {
'Content-type': 'application/json'
}
URL = 'https://osf.io/api/v1/search/'
def search_contributor(guid):
data = json.dumps({
'query': {
'query_string': {
'default_field': '_all',
'query': 'contributors_url{} AND (category:project OR category:component OR category:registration)'.format(guid),
'analyze_wildcard': True,
'lenient': True # TODO, may not want to do this
}
}
})
results = requests.post(URL, headers=HEADERS, data=data).json()
return [{
'title': x['title'],
'contributors': x['contributors'],
'contributors_url': x['contributors_url'],
'url': x['url']
} for x in results['results']]
def search_node(guid):
data = json.dumps({
'query': {
'match': {
'url': guid
}
}
})
results = requests.post(URL, headers=HEADERS, data=data).json()
return [{
'contributors': x['contributors'],
'contributors_url': x['contributors_url']
} for x in results['results']]
search_contributor('rnizy')
search_node('/h8sp7/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment