Last active
August 29, 2015 14:17
-
-
Save fabianvf/a1c77122d60556b70660 to your computer and use it in GitHub Desktop.
Graph data osf
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
# 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