Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions astroquery/tns/__init__.py
Original file line number Diff line number Diff line change
@@ -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']
34 changes: 34 additions & 0 deletions astroquery/tns/core.py
Original file line number Diff line number Diff line change
@@ -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
Loading