Skip to content

Commit

Permalink
Made the NomoRobo online lookup service optional.
Browse files Browse the repository at this point in the history
- Added the BLOCK_SERVICE to the configuration. Permitted values are "NOMOROBO" and "" (blank).
- Cleaned up the logging during testing.
- Closes #113
  • Loading branch information
emxsys committed Nov 4, 2020
1 parent 27215f2 commit e3cea4f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
8 changes: 8 additions & 0 deletions callattendant/app.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ BLOCK_NAME_PATTERNS = {"V[0-9]{15}": "Telemarketer Caller ID", }
# Example: {"P": "Private number", "O": "Out of area",}
BLOCK_NUMBER_PATTERNS = {}

# BLOCK_SERVICE: The name of the online service used to lookup robocallers and spam numbers.
# Currently, only NOMOROBO is supported and it is for the USA. Areas outside the USA should set
# to blank. When the online service is blank (disabled), only the blacklist and blocked
# name/number patterns are used to block numbers.
#
# Example: "NOMOROBO" (USA) or "" (disabled).
BLOCK_SERVICE = "NOMOROBO"


# BLOCKED_ACTIONS: A tuple containing a combination of the following actions:
# "greeting", "record_message", "voice_mail".
Expand Down
5 changes: 5 additions & 0 deletions callattendant/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import sys
import queue
import sqlite3
import time
from pprint import pprint
from shutil import copyfile

Expand Down Expand Up @@ -115,6 +116,10 @@ def process_calls(self):
# Instruct the modem to start feeding calls into the caller queue
self.modem.handle_calls(self.handle_caller)

# If testing, allow queue to be filled before processing for clean, readable logs
if self.config["TESTING"]:
time.sleep(1)

# Process incoming calls
while 1:
try:
Expand Down
1 change: 1 addition & 0 deletions callattendant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"PHONE_DISPLAY_FORMAT": "###-###-####",

"BLOCK_ENABLED": True,
"BLOCK_SERVICE": "NOMOROBO",
"BLOCK_NAME_PATTERNS": {"V[0-9]{15}": "Telemarketer Caller ID", },
"BLOCK_NUMBER_PATTERNS": {},

Expand Down
17 changes: 9 additions & 8 deletions callattendant/screening/callscreener.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,15 @@ def is_blacklisted(self, callerid):
reason = block["number_patterns"][key]
print(reason)
return True, reason
print(">> Checking nomorobo...")
result = self._nomorobo.lookup_number(number)
if result["spam"]:
reason = "{} with score {}".format(result["reason"], result["score"])
if self.config["DEBUG"]:
print(">>> {}".format(reason))
self.blacklist_caller(callerid, reason)
return True, reason
if block["service"].upper() == "NOMOROBO":
print(">> Checking nomorobo...")
result = self._nomorobo.lookup_number(number)
if result["spam"]:
reason = "{} with score {}".format(result["reason"], result["score"])
if self.config["DEBUG"]:
print(">>> {}".format(reason))
self.blacklist_caller(callerid, reason)
return True, reason
print("Caller has been screened")
return False, "Not found"
finally:
Expand Down

0 comments on commit e3cea4f

Please sign in to comment.