From 17a8b3783ec77de3f46dd958eb26e28597c44a97 Mon Sep 17 00:00:00 2001 From: markusbloch Date: Thu, 19 Mar 2015 17:54:19 +0000 Subject: [PATCH] FB_CALLMONITOR: using official API for reverse search on klicktel.de and search.ch git-svn-id: svn://svn.code.sf.net/p/fhem/code/trunk@8244 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/72_FB_CALLMONITOR.pm | 60 ++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/fhem/FHEM/72_FB_CALLMONITOR.pm b/fhem/FHEM/72_FB_CALLMONITOR.pm index 67050952d..08d2bfa1d 100755 --- a/fhem/FHEM/72_FB_CALLMONITOR.pm +++ b/fhem/FHEM/72_FB_CALLMONITOR.pm @@ -508,7 +508,7 @@ FB_CALLMONITOR_reverseSearch($$) { Log3 $name, 4, "FB_CALLMONITOR ($name) - using klicktel.de for reverse search of $number"; - $result = GetFileFromURL("http://www.klicktel.de/rueckwaertssuche/".$number, 5, undef, 1); + $result = GetFileFromURL("http://openapi.klicktel.de/searchapi/invers?key=0de6139a49055c37b9b2d7bb3933cb7b&number=".$number, 5, undef, 1); if(not defined($result)) { if(AttrVal($name, "reverse-search-cache", "0") eq "1") @@ -520,7 +520,7 @@ FB_CALLMONITOR_reverseSearch($$) } else { - if($result =~ /(.+?)<\/a>/) + if($result =~ /"displayname":"([^"]*?)"/) { $invert_match = $1; $invert_match = FB_CALLMONITOR_html2txt($invert_match); @@ -528,10 +528,6 @@ FB_CALLMONITOR_reverseSearch($$) undef($result); return $invert_match; } - elsif(not $result =~ /Leider wurde zu dieser Suche kein Eintrag gefunden/) - { - Log3 $name, 3, "FB_CALLMONITOR ($name) - the reverse search result for $number could not be extracted from klicktel.de. Please contact the FHEM community."; - } } } @@ -573,7 +569,7 @@ FB_CALLMONITOR_reverseSearch($$) { Log3 $name, 4, "FB_CALLMONITOR ($name) - using search.ch for reverse search of $number"; - $result = GetFileFromURL("http://tel.search.ch/?was=".$number, 5, undef, 1); + $result = GetFileFromURL("http://tel.search.ch/api/?key=b0b1207cb7c9d0048867de887aa9a4fd&maxnum=1&was=".$number, 5, undef, 1); if(not defined($result)) { if(AttrVal($name, "reverse-search-cache", "0") eq "1") @@ -586,18 +582,32 @@ FB_CALLMONITOR_reverseSearch($$) else { #Log 2, $result; - if($result =~ /]*>.*?

(.+?)<\/h1>.*?<\/section>/s) + if($result =~ /(.+?)<\/entry>/s) { - $invert_match = $1; + my $xml = $1; + + $invert_match = ""; + + if($xml =~ /(.+?)<\/tel:firstname>/) + { + $invert_match .= $1; + } + + if($xml =~ /(.+?)<\/tel:name>/) + { + $invert_match .= " $1"; + } + + if($xml =~ /(.+?)<\/tel:occupation>/) + { + $invert_match .= ", $1"; + } + $invert_match = FB_CALLMONITOR_html2txt($invert_match); FB_CALLMONITOR_writeToCache($hash, $number, $invert_match) if(AttrVal($name, "reverse-search-cache", "0") eq "1"); undef($result); return $invert_match; } - elsif(not $result =~ /Keine Eintr.ge gefunden/) - { - Log3 $name, 3, "FB_CALLMONITOR ($name) - the reverse search result for $number could not be extracted from search.ch. Please contact the FHEM community."; - } } } @@ -659,17 +669,17 @@ sub FB_CALLMONITOR_html2txt($) $string =~ s/ / /g; $string =~ s/&/&/g; - $string =~ s/(\xe4|ä)/ä/g; - $string =~ s/(\xc4|Ä)/Ä/g; - $string =~ s/(\xf6|ö)/ö/g; - $string =~ s/(\xd6|Ö)/Ö/g; - $string =~ s/(\xfc|ü)/ü/g; - $string =~ s/(\xdc|Ü)/Ü/g; + $string =~ s/(\xe4|ä|\\u00e4|\\u00E4)/ä/g; + $string =~ s/(\xc4|Ä|\\u00c4|\\u00C4)/Ä/g; + $string =~ s/(\xf6|ö|\\u00f6|\\u00F6)/ö/g; + $string =~ s/(\xd6|Ö|\\u00d6|\\u00D6)/Ö/g; + $string =~ s/(\xfc|ü|\\u00fc|\\u00FC)/ü/g; + $string =~ s/(\xdc|Ü|\\u00dc|\\u00DC)/Ü/g; $string =~ s/(\xdf|ß)/ß/g; $string =~ s/<.+?>//g; $string =~ s/(^\s+|\s+$)//g; - return $string; + return trim($string); } @@ -1409,6 +1419,11 @@ sub FB_CALLMONITOR_readPassword($;$)
  • missed_call - This event will be raised in case of a missing incoming call. If available, also the name of the calling number will be displayed.
  • missed_call_line - Will be raised together with "missed_call". It shows the number of the internal line which received the missed call.
  • +
    + Legal Notice:

    +
      +
    • klicktel.de reverse search is powered by telegate MEDIA
    • +
    @@ -1538,6 +1553,11 @@ sub FB_CALLMONITOR_readPassword($;$)
  • missed_call - Dieses Event wird nur generiert, wenn ein eingehender Anruf nicht beantwortet wird. Sofern der Name dazu bekannt ist, wird dieser ebenfalls mit angezeigt.
  • missed_call_line - Analog zu "missed_call" wird dieses Event nur generiert, wenn ein eingehender Anruf nicht beantwortet wird. Es zeigt die Rufnummer an über, den dieser unbeantwortete Anruf eingegangen ist.
  • +
    + Rechtlicher Hinweis:

    +
      +
    • klicktel.de reverse search ist powered by telegate MEDIA
    • +