Files
galaxy/scripts/api/search.py
T
Nicola Soranzo 21b44bf348 Fix all E201 and E202 style errors
using the following command:
```
autopep8 -i -r --exclude $(sed -e 's|^|./|' -e 's|/$||' .ci/flake8_blacklist.txt | paste -sd,) --select E201,E202 .
```
2017-08-17 11:35:39 +01:00

60 lines
1.8 KiB
Python

"""
Sample script for Galaxy Search API
"""
from __future__ import print_function
import json
import requests
import sys
class RemoteGalaxy(object):
def __init__(self, url, api_key):
self.url = url
self.api_key = api_key
def get(self, path):
c_url = self.url + path
params = {}
params['key'] = self.api_key
req = requests.get(c_url, params=params)
return req.json()
def post(self, path, payload):
c_url = self.url + path
params = {}
params['key'] = self.api_key
req = requests.post(c_url, data=json.dumps(payload), params=params, headers={'Content-Type': 'application/json'})
return req.json()
if __name__ == "__main__":
server = sys.argv[1]
api_key = sys.argv[2]
rg = RemoteGalaxy(server, api_key)
print("select name, id, file_size from hda")
print(rg.post("/api/search", {"query": "select name, id, file_size from hda"}))
print("select name from hda")
print(rg.post("/api/search", {"query": "select name from hda"}))
print("select name, model_class from ldda")
print(rg.post("/api/search", {"query": "select name, model_class from ldda"}))
print("select * from history")
print(rg.post("/api/search", {"query": "select * from history"}))
print("select * from tool")
print(rg.post("/api/search", {"query": "select * from tool"}))
print("select * from workflow")
print(rg.post("/api/search", {"query": "select * from workflow"}))
print("select id, name from history where name='Unnamed history'")
print(rg.post("/api/search", {"query": "select id, name from history where name='Unnamed history'"}))
print("select * from history where name='Unnamed history'")
print(rg.post("/api/search", {"query": "select * from history where name='Unnamed history'"}))