# Path: libAirSuck/asLog.py
# class asLog():
#     """
#     airSuck logging class.
#     """
#     
#     def __init__(self, loggingMode="stdout"):
#         """
#         asLog constructor
#         """
#         
#         # Check for acceptable logging mode.
#         if loggingMode in ('stdout', 'syslog', 'none'):
#             # Set class-wide logging mode.
#             self.mode = loggingMode
#         else:
#             raise ValueError("Valid loging mode not specified. Please use 'stdout', 'syslog', or 'none'.")
#         
#         if loggingMode == "syslog":
#             syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
#     
#     def __logStdout(self, message):
#         """
#         Log a message to stdout with a UTC timestamp.
#         """
#         # Get timestamp.
#         dts = str(datetime.datetime.utcnow())
#         
#         # Keep the log looking pretty and uniform.
#         if len(dts) == 19:
#             dts = dts + ".000000"
#         
#         # Dump the message.
#         sys.stdout.write("%s - %s\n" %(dts, message))
#     
#     def __logSyslog(self, message, sev=syslog.LOG_NOTICE):
#         """
#         Log a message to syslog.
#         """
#         
#         # Log it.
#         syslog.syslog(sev, message)
#     
#     def log(self, message):
#         """
#         Log a message.
#         """
#         
#         try:
#             # If we don't want to do anything...
#             if self.mode == "stdout":
#                 # Log to stdout.
#                 self.__logStdout(message)
#             
#             elif self.mode == "syslog":
#                 # Log to syslog. Not fully implemented yet.
#                 self.__logSyslog(message)
#             
#             elif self.mode == "none":
#                 # This logs absolutely nothing.
#                 None
#         
#         except KeyboardInterrupt:
#             raise KeyboardInterrupt
#         
#         except:
#             tb = traceback.format_exc()
#             print("airSuck logger failure:\n%s" %tb)


	import config
import sys
import redis
import time
import json
import threading
import time
import traceback
from libAirSuck import asLog
from socket import socket
from pprint import pprint
        dump1090Sock = socket()
        
        # Infinite loop
        while True:
            try:
                # Attempt a connection.
                logger.log("Connecting to %s:%s" %(dump1090Dst["host"], dump1090Dst["port"]))
                
                # Connect up.
                dump1090Sock.connect((dump1090Dst["host"], dump1090Dst["port"]))
                logger.log("Connected.")
                
                # Handle incoming data.
                for work in self.pubsub.listen():
                    self.worker(work, dump1090Sock)
                
                dump1090Sock.close()
                
            except KeyboardInterrupt:
                quit()
                
            except:
                tb = traceback.format_exc()
                logger.log("Failed to connect to %s:%s\n%s" %(dump1090Dst["host"], dump1090Dst["port"], tb))
                logger.log("Sleeping %s sec" %dump1090Dst["reconnectDelay"])
                time.sleep(dump1090Dst["reconnectDelay"])

# Start up.
if __name__ == "__main__":
    # Set up the logger.

# Path: libAirSuck/asLog.py
# class asLog():
#     """
#     airSuck logging class.
#     """
#     
#     def __init__(self, loggingMode="stdout"):
#         """
#         asLog constructor
#         """
#         
#         # Check for acceptable logging mode.
#         if loggingMode in ('stdout', 'syslog', 'none'):
#             # Set class-wide logging mode.
#             self.mode = loggingMode
#         else:
#             raise ValueError("Valid loging mode not specified. Please use 'stdout', 'syslog', or 'none'.")
#         
#         if loggingMode == "syslog":
#             syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
#     
#     def __logStdout(self, message):
#         """
#         Log a message to stdout with a UTC timestamp.
#         """
#         # Get timestamp.
#         dts = str(datetime.datetime.utcnow())
#         
#         # Keep the log looking pretty and uniform.
#         if len(dts) == 19:
#             dts = dts + ".000000"
#         
#         # Dump the message.
#         sys.stdout.write("%s - %s\n" %(dts, message))
#     
#     def __logSyslog(self, message, sev=syslog.LOG_NOTICE):
#         """
#         Log a message to syslog.
#         """
#         
#         # Log it.
#         syslog.syslog(sev, message)
#     
#     def log(self, message):
#         """
#         Log a message.
#         """
#         
#         try:
#             # If we don't want to do anything...
#             if self.mode == "stdout":
#                 # Log to stdout.
#                 self.__logStdout(message)
#             
#             elif self.mode == "syslog":
#                 # Log to syslog. Not fully implemented yet.
#                 self.__logSyslog(message)
#             
#             elif self.mode == "none":
#                 # This logs absolutely nothing.
#                 None
#         
#         except KeyboardInterrupt:
#             raise KeyboardInterrupt
#         
#         except:
#             tb = traceback.format_exc()
#             print("airSuck logger failure:\n%s" %tb)


# Path: sub2Dump1090.py
	import config
import sys
import redis
import time
import json
import threading
import time
import traceback
from libAirSuck import asLog
from socket import socket
from pprint import pprint

        dump1090Sock = socket()
        
        # Infinite loop
        while True:
            try:
                # Attempt a connection.
                logger.log("Connecting to %s:%s" %(dump1090Dst["host"], dump1090Dst["port"]))
                
                # Connect up.
                dump1090Sock.connect((dump1090Dst["host"], dump1090Dst["port"]))
                logger.log("Connected.")
                
                # Handle incoming data.
                for work in self.pubsub.listen():
                    self.worker(work, dump1090Sock)
                
                dump1090Sock.close()
                
            except KeyboardInterrupt:
                quit()
                
            except:
                tb = traceback.format_exc()
                logger.log("Failed to connect to %s:%s\n%s" %(dump1090Dst["host"], dump1090Dst["port"], tb))
                logger.log("Sleeping %s sec" %dump1090Dst["reconnectDelay"])
                time.sleep(dump1090Dst["reconnectDelay"])

# Start up.
if __name__ == "__main__":
    # Set up the logger.

    logger = asLog('stdout')