Because I have always assumed that Google would aggregate tracking information across its various web properties, I have long used
Scroogle for most of my web searches. It turns out I was right: every mail message you read, every search you perform, and every page you visit with a Google-served ad or analytics tracker is linked to your unique identity. With Google making Scroogle unreliable lately, I have given
Duck Duck Go (
implemented in a mixture of Perl and JavaScript) another look, and I have been pleasantly surprised: it gives pretty good results with an uncluttered interface and a
sane privacy policy.
It also has an easy-to-use API, without license keys or similar BS. While there are a couple of CPAN modules for this API, they're pretty heavy for such a simple task. Here's a simple script that, on Perl >= 5.14, has no non-core dependencies:
use JSON::PP;
use HTTP::Tiny;
sub ddg_clean
{
my $res = shift;
for my $k (keys %$res) {
delete $res->{$k} if $res->{$k} eq '';
if (ref $res->{$k} eq 'HASH') {
ddg_clean($res->{$k});
delete $res->{$k} unless keys %{$res->{$k}};
} elsif (ref $res->{$k} eq 'ARRAY') {
ddg_clean($_) for @{$res->{$k}};
delete $res->{$k} unless @{$res->{$k}};
}
}
}
sub ddg
{
my $q = shift;
my $h = new HTTP::Tiny;
my $res = $h->get(
'http://api.duckduckgo.com/?'
. $h->www_form_urlencode({ format => 'json', q => $q }));
die unless $res->{success};
ddg_clean($res = decode_json($res->{content}));
$res;
}
sub INDENT() { ' ' }
sub ddg_format
{
my ($it, $lev) = @_;
if (!ref $it) {
wrap(INDENT x $lev, INDENT x $lev, $it);
} elsif (ref $it eq 'HASH') {
join "\n", map {
my $val = ddg_format($it->{$_}, $lev+1);
if ($val =~ /\n/) {
INDENT x $lev . "$_:\n$val";
} else {
$val =~ s/^\s+//;
INDENT x $lev . "$_: $val";
}
} sort keys %$it;
} else {
join "\n", map { ddg_format($_, $lev+1) } @$it;
}
}
if (!defined caller) {
eval 'use Text::Wrap';
print ddg_format(ddg("@ARGV"), 0), "\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.