def __init__(self, config): """ The constructor initializes and starts the Call Attendant. :param config: the application config dict """ # The application-wide configuration self.config = config # Thread synchonization object self._stop_event = threading.Event() # Open the database if self.config["TESTING"]: self.db = sqlite3.connect(":memory:") else: self.db = sqlite3.connect(self.config['DB_FILE']) # Create a synchronized queue for incoming callers from the modem self._caller_queue = queue.Queue() # Hardware subsystem # Initialize the visual indicators (LEDs) self.approved_indicator = ApprovedIndicator( self.config.get("GPIO_LED_APPROVED_PIN"), self.config.get("GPIO_LED_APPROVED_BRIGHTNESS", 100)) self.blocked_indicator = BlockedIndicator( self.config.get("GPIO_LED_BLOCKED_PIN"), self.config.get("GPIO_LED_BLOCKED_BRIGHTNESS", 100)) # Create (and open) the modem self.modem = Modem(self.config) self.config[ "MODEM_ONLINE"] = self.modem.is_open # signal the webapp not online # Screening subsystem self.logger = CallLogger(self.db, self.config) self.screener = CallScreener(self.db, self.config) # Messaging subsystem self.voice_mail = VoiceMail(self.db, self.config, self.modem) # Start the User Interface subsystem (Flask) # Skip if we're running functional tests, because when testing # we use a memory database which can't be shared between threads. if not self.config["TESTING"]: print("Starting the Flask webapp") webapp.start(self.config)
def __init__(self, config): """ The constructor initializes and starts the Call Attendant. :param config: the application config dict """ # The application-wide configuration self.config = config # Open the database db_path = None if self.config["TESTING"]: self.db = sqlite3.connect(":memory:") else: self.db = sqlite3.connect( os.path.join(self.config['ROOT_PATH'], self.config['DATABASE'])) # Create a synchronized queue for incoming callers from the modem self._caller_queue = queue.Queue() # Screening subsystem self.logger = CallLogger(self.db, self.config) self.screener = CallScreener(self.db, self.config) # Hardware subsystem # Create the modem with the callback functions that it invokes # when incoming calls are received. self.modem = Modem(self.config, self.phone_ringing, self.handle_caller) # Initialize the visual indicators (LEDs) self.approved_indicator = ApprovedIndicator() self.blocked_indicator = BlockedIndicator() self.ring_indicator = RingIndicator() # Start the User Interface subsystem (Flask) # Skip if we're running functional tests, because when testing # we use a memory database which can't be shared between threads. if not self.config["TESTING"]: print("Staring the Flask webapp") webapp.start(config)
def __init__(self): """The constructor initializes and starts the Call Attendant""" self.settings = {} self.settings[ "db_name"] = "callattendant.db" # SQLite3 DB to store incoming call log, whitelist and blacklist self.settings[ "screening_mode"] = "whitelist_and_blacklist" # no_screening, whitelist_only, whitelist_and_blacklist, blacklist_only self.settings["bad_cid_patterns"] = "" # regex name patterns to ignore self.settings["ignore_private_numbers"] = False # Ignore "P" CID names self.settings["ignore_unknown_numbers"] = True # Ignore "O" CID names self.settings["block_calls"] = True self.db = sqlite3.connect(self.settings["db_name"]) # The current/last caller id self._caller_queue = Queue() # Visual indicators (LEDs) self.approved_indicator = ApprovedIndicator() self.blocked_indicator = BlockedIndicator() self.ring_indicator = RingIndicator() # Telephony subsystems self.logger = CallLogger(self.db) self.screener = CallScreener(self.db) self.modem = Modem(self) self.modem.handle_calls() # User Interface subsystem webapp.start() # Run the app while 1: """Processes incoming callers with logging and screening.""" # Wait (blocking) for a caller caller = self._caller_queue.get() # Perform the call screening mode = self.settings["screening_mode"] whitelisted = False blacklisted = False if mode in ["whitelist_only", "whitelist_and_blacklist"]: print "Checking whitelist(s)" if self.screener.is_whitelisted(caller): whitelisted = True caller["NOTE"] = "Whitelisted" self.approved_indicator.turn_on() if not whitelisted and mode in [ "blacklist_only", "whitelist_and_blacklist" ]: print "Checking blacklist(s)" if self.screener.is_blacklisted(caller): blacklisted = True caller["NOTE"] = "Blacklisted" self.blocked_indicator.turn_on() if self.settings["block_calls"]: #~ self.modem.play_audio("sample.wav") #~ self.modem.hang_up() self.modem.block_call() # Log every call to the database self.logger.log_caller(caller)