From: fredrik Date: Wed, 31 Jan 2007 21:12:54 +0000 (+0000) Subject: Initial import. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=178e242170f48c475af8ccbe19f68bb35a6facfe;p=utils.git Initial import. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/utils@842 959494ce-11ee-0310-bf91-de5d638817bd --- diff --git a/tel2name b/tel2name new file mode 100755 index 0000000..562b133 --- /dev/null +++ b/tel2name @@ -0,0 +1,99 @@ +#!/usr/bin/perl + +binmode(STDOUT, ":utf8"); + +use LWP::UserAgent; +use HTML::Entities; +use Encode; + +sub yplookup { + my($tel); + ($tel) = @_; + + $ua = LWP::UserAgent->new; + $ua->agent("tel2name/1.0 "); + $res = $ua->request(HTTP::Request->new("GET", "http://www.eniro.se/query?what=yp&search_word=$tel")); + + return undef unless $res->is_success; + + $html = $res->content; + + match: while($html =~ /\s*([^<]*[^\s<])\s*<\/span>/ig) { + $match = decode_entities($1); + for $prev (@matches) { + next match if $prev eq $match; + } + push @matches, $match; + } + for $match (@matches) { + print "$match\n"; + } +} + +sub wplookup { + my($tel); + ($tel) = @_; + + $ua = LWP::UserAgent->new; + $ua->agent("tel2name/1.0 "); + $res = $ua->request(HTTP::Request->new("GET", "http://www.eniro.se/query?what=wp&phone_number=$tel")); + + return undef unless $res->is_success; + + $html = $res->content; + + match: while($html =~ /]*>\s*\\s*([^<]*[^\s<])\s*<\/span>/ig) { + $match = decode_entities($1); + for $prev (@matches) { + next match if $prev eq $match; + } + push @matches, $match; + } + for $match (@matches) { + print "$match\n"; + } +} + +$tel = $ARGV[0]; + +if(open NT, $ENV{"HOME"} . "/phone/nametab") { + while() { + if(/$tel\s(.*)$/) { + print "$1\n"; + exit 0; + } + } + close NT; +} + +$yppid = open YP, "-|"; +if($yppid == 0) { + yplookup $tel; + exit 0; +} +$wppid = open WP, "-|"; +if($wppid == 0) { + wplookup $tel; + exit 0; +} +binmode(YP, ":utf8"); +binmode(WP, ":utf8"); + +match: while() { + chomp; + for $prev (@matches) { + next match if $prev eq $_; + } + push @matches, $_; +} +match: while() { + chomp; + for $prev (@matches) { + next match if $prev eq $_; + } + push @matches, $_; +} + +for $match (@matches) { + print "$match\n"; +}