From 718ea95a0967db9192fb8abaf828d93c0c3b67ba Mon Sep 17 00:00:00 2001 From: TriangleBoy <89360730+TriangleBoy@users.noreply.github.com> Date: Thu, 26 Mar 2026 17:09:04 -0400 Subject: [PATCH 1/2] Untested TNS search capability minus conversion to acceptable astroquery output --- astroquery/tns/__init__.py | 25 ++++++++++++++++++++++++ astroquery/tns/core.py | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 astroquery/tns/__init__.py create mode 100644 astroquery/tns/core.py 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..9e7bd87ce0 --- /dev/null +++ b/astroquery/tns/core.py @@ -0,0 +1,40 @@ +# 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_helper(self, *args): + search_obj = [] + for arg in args: + search_obj.append(arg) + + search_url = "https://" + self._server + "/api/get/search" + tns_marker = self._set_bot_tns_marker(self._bot_id, self._bot_name) + headers = {'User-Agent': tns_marker} + json_file = OrderedDict(search_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 + + + def query_object(self, *args): + if len(args) == 1 and isinstance(args[0], str): + return self._query_object_helper(("objname", args[0])) + return self._query_object_helper(*args) From 0b62079f648411c66e3e6e9b1d58d8586331615f Mon Sep 17 00:00:00 2001 From: TriangleBoy <89360730+TriangleBoy@users.noreply.github.com> Date: Thu, 26 Mar 2026 17:36:55 -0400 Subject: [PATCH 2/2] Minor refactoring to fit with astroquery API better --- astroquery/tns/core.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/astroquery/tns/core.py b/astroquery/tns/core.py index 9e7bd87ce0..3980a325ac 100644 --- a/astroquery/tns/core.py +++ b/astroquery/tns/core.py @@ -19,22 +19,16 @@ def __init__(self): 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_helper(self, *args): - search_obj = [] + + def query_object(self, *args): + get_obj = [] for arg in args: - search_obj.append(arg) + get_obj.append(arg) - search_url = "https://" + self._server + "/api/get/search" + 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(search_obj) + 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 - - - def query_object(self, *args): - if len(args) == 1 and isinstance(args[0], str): - return self._query_object_helper(("objname", args[0])) - return self._query_object_helper(*args) + # TODO: convert the response to what is expected of an astroquery module \ No newline at end of file