|
@@ -90,7 +90,6 @@ def is_in_ktipp_blacklist(a_number):
|
|
|
the_number = the_number.replace("+", "")
|
|
|
|
|
|
url = KTIP_LOOKUP_URL.replace("{$number$}", the_number)
|
|
|
- log("KTIP lookup : " + url)
|
|
|
response = ""
|
|
|
try:
|
|
|
response = urllib2.urlopen(url).read()
|
|
@@ -102,7 +101,6 @@ def is_in_ktipp_blacklist(a_number):
|
|
|
|
|
|
def is_in_shiansw_blacklist(a_number):
|
|
|
url = SHOULDIANSWER_LOOKUP_URL.replace("{$number$}", a_number)
|
|
|
- log("SIANSW lookup : " + url)
|
|
|
response = ""
|
|
|
try:
|
|
|
response = urllib2.urlopen(url).read()
|
|
@@ -112,11 +110,6 @@ def is_in_shiansw_blacklist(a_number):
|
|
|
return '<div class="review_score negative"></div>' in response
|
|
|
|
|
|
|
|
|
-def log(msg):
|
|
|
- syslog.syslog(msg)
|
|
|
- print(msg)
|
|
|
-
|
|
|
-
|
|
|
def get_wav_duration(fname):
|
|
|
with contextlib.closing(wave.open(fname, 'r')) as f:
|
|
|
frames = f.getnframes()
|
|
@@ -130,6 +123,11 @@ def sleep(duration):
|
|
|
|
|
|
|
|
|
class SipConnection(object):
|
|
|
+ def log(self, msg):
|
|
|
+ to_show = str(self) + ": " + msg
|
|
|
+ print(to_show)
|
|
|
+ syslog.syslog(to_show)
|
|
|
+
|
|
|
def say(self, core):
|
|
|
if self._conversation.status is not ConversationStatus.IMTALKING:
|
|
|
self._conversation.status = ConversationStatus.IMTALKING
|
|
@@ -145,7 +143,7 @@ class SipConnection(object):
|
|
|
self._replies_pos = 1
|
|
|
|
|
|
duration = get_wav_duration(voice_filename)
|
|
|
- log("Saying : " + voice_filename)
|
|
|
+ self.log("Saying : " + voice_filename)
|
|
|
|
|
|
core.play_file = voice_filename
|
|
|
|
|
@@ -191,37 +189,40 @@ class SipConnection(object):
|
|
|
sleep(0.01)
|
|
|
previous_status = self._conversation.status
|
|
|
|
|
|
- log("Worker is quitting")
|
|
|
+ self.log("Worker is quitting")
|
|
|
|
|
|
- @staticmethod
|
|
|
- def registration_state_changed(core, call, state, message):
|
|
|
- log("Registration status: " + message)
|
|
|
+ def registration_state_changed(self, core, call, state, message):
|
|
|
+ # Le client se ré-enregistre a de multiple reprise, on
|
|
|
+ # s'en tappe un peu d'en être informé.
|
|
|
+ if message != self._registration_previous_message:
|
|
|
+ self.log("Registration status: " + message)
|
|
|
+ self._registration_previous_message = message
|
|
|
|
|
|
def call_state_changed(self, core, call, state, message):
|
|
|
- log("state changed : " + message)
|
|
|
+ self.log("state changed : " + message)
|
|
|
|
|
|
if state == linphone.CallState.Released:
|
|
|
# Let's convert wav to mp3
|
|
|
if call.current_params.record_file is not None and os.path.isfile(call.current_params.record_file):
|
|
|
- log("Saving to mp3 : " + call.current_params.record_file)
|
|
|
+ self.log("Saving to mp3 : " + call.current_params.record_file)
|
|
|
subprocess.call('lame --quiet --preset insane %s' % call.current_params.record_file, shell=True)
|
|
|
os.remove(call.current_params.record_file)
|
|
|
|
|
|
if state == linphone.CallState.IncomingReceived:
|
|
|
- log("Incoming call : {}".format(call.remote_address.username))
|
|
|
+ self.log("Incoming call : {}".format(call.remote_address.username))
|
|
|
|
|
|
self._replies_pos = 0
|
|
|
|
|
|
if is_in_blacklists(call.remote_address.username):
|
|
|
- log("telemarketer calling : " + call.remote_address.username)
|
|
|
+ self.log("telemarketer calling : " + call.remote_address.username)
|
|
|
|
|
|
call_params = core.create_call_params(call)
|
|
|
- os.makedirs(current_dir + "/out")
|
|
|
+ os.makedirs(current_dir + "/out", exist_ok=True)
|
|
|
a_file = current_dir + "/out/call_from_" + slugify(call.remote_address.username) + \
|
|
|
"_" + datetime.now().strftime(
|
|
|
'%Y-%m-%d_%Hh%Mmn%Ss') + ".wav"
|
|
|
|
|
|
- log(a_file)
|
|
|
+ self.log("Recording to : " + a_file)
|
|
|
|
|
|
call_params.record_file = a_file
|
|
|
|
|
@@ -242,11 +243,11 @@ class SipConnection(object):
|
|
|
return self
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, traceback):
|
|
|
- log(str(self) + ": cleaning on exit ...")
|
|
|
+ self.log(str(self) + ": cleaning on exit ...")
|
|
|
os.unlink(self._incoming_stream_file)
|
|
|
|
|
|
def start(self):
|
|
|
- log("starting " + str(self))
|
|
|
+ self.log("starting ")
|
|
|
self._core.use_files = True
|
|
|
self._core.record_file = self._incoming_stream_file
|
|
|
|
|
@@ -282,6 +283,8 @@ class SipConnection(object):
|
|
|
self._password = password
|
|
|
self._is_quitting = False
|
|
|
|
|
|
+ self._registration_previous_message = ""
|
|
|
+
|
|
|
self._conversation = Conversation()
|
|
|
self._replies_pos = 0
|
|
|
self._volume_threshold = VOLUME_THRESHOLD
|