#!/usr/bin/env python
#
# Copyright (C) 2014-2016  Leo Singer
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
"""
Example VOEvent listener that saves all incoming VOEvents to disk.
"""
__author__ = "Leo Singer <leo.singer@ligo.org>"

# Imports
import argparse
import logging
import gcn
import gcn.handlers
from gcn.cmdline import HostPortAction

# Command line interface
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('addr', default='68.169.57.253:8099', action=HostPortAction,
                    help='Server host and port (default: %(default)s)')
parser.add_argument('--version', action='version',
                    version='pygcn ' + gcn.__version__)
args = parser.parse_args()

# Set up logger
logging.basicConfig(level=logging.INFO)

# Listen for GCN notices (until interrupted or killed)
gcn.listen(host=args.addr.host, port=args.addr.port,
           handler=gcn.handlers.archive)
