|
@@ -69,6 +69,12 @@ THREADS_MUST_QUIT = False
|
|
|
KTIP_LOOKUP_URL = "https://www.ktipp.ch/service/warnlisten/detail/?warnliste_id=7&ajax=ajax-search-form&keyword={" \
|
|
|
"$number$}"
|
|
|
|
|
|
+SHOULDIANSWER_LOOKUP_URL = "https://ch.shouldianswer.net/telefonnummer/{$number$}"
|
|
|
+
|
|
|
+
|
|
|
+def is_in_blacklists(a_number):
|
|
|
+ return is_in_local_blacklist(a_number) or is_in_ktipp_blacklist(a_number) or is_in_shiansw_blacklist(a_number)
|
|
|
+
|
|
|
|
|
|
def is_in_local_blacklist(a_number):
|
|
|
black_list = current_dir + "/blacklist.txt"
|
|
@@ -83,8 +89,26 @@ def is_in_ktipp_blacklist(a_number):
|
|
|
# 0 Einträge
|
|
|
|
|
|
url = KTIP_LOOKUP_URL.replace("{$number$}", a_number)
|
|
|
+ log("KTIP lookup : " + url)
|
|
|
+ response = ""
|
|
|
+ try:
|
|
|
+ response = urllib2.urlopen(url).read()
|
|
|
+ except urllib2.HTTPError:
|
|
|
+ pass
|
|
|
+
|
|
|
+ return "0 Eintr" not in response
|
|
|
+
|
|
|
+
|
|
|
+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()
|
|
|
+ except urllib2.HTTPError:
|
|
|
+ pass
|
|
|
|
|
|
- return "0 Eintr" not in urllib2.urlopen(url).read()
|
|
|
+ return '<div class="review_score negative"></div>' in response
|
|
|
|
|
|
|
|
|
def log(msg):
|
|
@@ -140,7 +164,7 @@ def call_state_changed(core, call, state, message):
|
|
|
if state == linphone.CallState.Released:
|
|
|
# Let's convert wav to mp3
|
|
|
log("Converting output from wav to mp3")
|
|
|
- if os.path.isfile(call.current_params.record_file):
|
|
|
+ if call.current_params.record_file is not None and os.path.isfile(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)
|
|
|
|
|
@@ -149,12 +173,12 @@ def call_state_changed(core, call, state, message):
|
|
|
|
|
|
replies_pos = 0
|
|
|
|
|
|
- if is_in_local_blacklist(call.remote_address.username) or is_in_ktipp_blacklist(call.remote_address.username):
|
|
|
+ if is_in_blacklists(call.remote_address.username):
|
|
|
log("telemarketer calling : " + call.remote_address.username)
|
|
|
|
|
|
call_params = core.create_call_params(call)
|
|
|
a_file = current_dir + "/out/call_from_" + slugify(call.remote_address.username) + \
|
|
|
- "_" + datetime.now().strftime(
|
|
|
+ "_" + datetime.now().strftime(
|
|
|
'%Y-%m-%d_%Hh%Mmn%Ss') + ".wav"
|
|
|
|
|
|
log(a_file)
|
|
@@ -175,14 +199,6 @@ def call_state_changed(core, call, state, message):
|
|
|
say(core)
|
|
|
|
|
|
|
|
|
-def global_state_changed(*args, **kwargs):
|
|
|
- log("global_state_changed: %r %r" % (args, kwargs))
|
|
|
-
|
|
|
-
|
|
|
-def registration_state_changed(core, call, state, message):
|
|
|
- log("registration_state_changed: " + str(state) + ", " + message)
|
|
|
-
|
|
|
-
|
|
|
def incoming_stream_worker(core, call):
|
|
|
global conversation
|
|
|
log("Worker is starting")
|
|
@@ -229,9 +245,7 @@ def incoming_stream_worker(core, call):
|
|
|
def main():
|
|
|
log("lenny is starting ...")
|
|
|
callbacks = {
|
|
|
- 'call_state_changed': call_state_changed,
|
|
|
- 'registration_state_changed': registration_state_changed,
|
|
|
- 'global_state_changed': global_state_changed,
|
|
|
+ 'call_state_changed': call_state_changed
|
|
|
}
|
|
|
|
|
|
username = "621"
|
|
@@ -261,9 +275,14 @@ def main():
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
-
|
|
|
try:
|
|
|
main()
|
|
|
except KeyboardInterrupt:
|
|
|
THREADS_MUST_QUIT = True
|
|
|
print "Bye"
|
|
|
+
|
|
|
+# TODO : créer un fichier de config
|
|
|
+# TODO : pouvoir s'enregistrer sur plusieurs comptes SIP
|
|
|
+# TODO : Que le stream entrant utilise un fichier temporaire
|
|
|
+# TODO : De pouvoir utiliser des mp3 pour gagner de la place, qu'on convertit au vol en wav, puis qu'on efface.
|
|
|
+# TODO : Ecrire le readme
|