diff --git a/astroquery/tns/__init__.py b/astroquery/tns/__init__.py new file mode 100644 index 0000000000..1a556dbb87 --- /dev/null +++ b/astroquery/tns/__init__.py @@ -0,0 +1,25 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst +""" +Transient Name Server query tool +---------------------------------- + +:Author: Noah M. Glimcher (brainsonfire42@gmail.com) + +""" +from astropy import config as _config + +class Conf(_config.ConfigNamespace): + """ Configuration parameters for `astroquery.tns` """ + + timeout = _config.ConfigItem(120, "Timeout in seconds.") + api_url = _config.ConfigItem("sandbox.wis-tns.org", "The endpoint URL") # Sandbox TODO: switch to production url "www.wis-tns.org" + + bot_name = _config.ConfigItem("", "Your TNS bot name") + bot_id = _config.ConfigItem("", "Your TNS bot ID") + api_key = _config.ConfigItem("", "Your TNS API key") + +conf = Conf() + +from .core import TnsClass + +__all__ = ['TnsClass', 'conf'] \ No newline at end of file diff --git a/astroquery/tns/core.py b/astroquery/tns/core.py new file mode 100644 index 0000000000..3980a325ac --- /dev/null +++ b/astroquery/tns/core.py @@ -0,0 +1,34 @@ +# Licensed under a 3-clause BSD style license - see LICENSE.rst + +import astropy +from ..query import BaseQuery +from . import conf +from ..utils.class_or_instance import class_or_instance +from collections import OrderedDict +import json + +class TnsClass(BaseQuery): + + def __init__(self): + self._server = conf.server + self._bot_name = conf.bot_name + self._bot_id = conf.bot_id + self._api_key = conf.api_key + # TODO: add login + pass + + def _set_bot_tns_marker(bot_id, bot_name): + return 'tns_marker{"tns_id": "' + str(bot_id) + '", "type": "bot", "name": "' + bot_name + '"}' + + def query_object(self, *args): + get_obj = [] + for arg in args: + get_obj.append(arg) + + search_url = "https://" + self._server + "/api/get/object" + tns_marker = self._set_bot_tns_marker(self._bot_id, self._bot_name) + headers = {'User-Agent': tns_marker} + json_file = OrderedDict(get_obj) + search_data = {'api-key': self._api_key, 'data':json.dumps(json_file)} + response = self._request("POST", search_url, headers=headers, data=search_data) + # TODO: convert the response to what is expected of an astroquery module \ No newline at end of file