/**
* @file DuckDuckGo/API.php
* This file provides the base class to interface with the DuckDuckGo API.
* It will also include any necessary classes.
* Simple example:
* $api = new DuckDuckGo\API();
* $info = $api->zeroClickQuery('Internet Relay Chat');
* echo $info->definition;
namespace DuckDuckGo;
/* Include the necessary classes. */
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'APIResult.php';
/**
* The API base URL. This defaults to api.duckduckgo.com.
$this->noDisambiguations = FALSE;
$this->baseURL = 'api.duckduckgo.com';
#include "duckduckgo.h"
DuckDuckGo::DuckDuckGo(QObject *parent, const QVariantList& args)
Q_UNUSED(args);
setObjectName(QLatin1String("DuckDuckGo"));
addSyntax(Plasma::RunnerSyntax(QLatin1String( "duckduckgo :q:" ), i18n("Lists the search entries matching the query, using DuckDuckGo search")));
addSyntax(Plasma::RunnerSyntax(QLatin1String( "wolfram :q:" ), i18n("Searches using Wolfram Alpha, powered by DuckDuckGo")));
addSyntax(Plasma::RunnerSyntax(QLatin1String( "define :q:" ), i18n("Defines words using dictionaries, powered by DuckDuckGo")));
setSpeed(SlowSpeed);
KUrl url = KUrl("http://api.duckduckgo.com/?q=futurama+characters&format=json&pretty=1");
// "http://api.duckduckgo.com/?q=define+ostensibly&format=json&pretty=1");
from __common__ import shorten_url, format_responses
MODULE_NAME = 'DuckDuckGo Instance Answer Search'
MODULE_ENABLE = True
MODULE_TYPE = 'command'
DUCKDUCKGO_URL = u'http://api.duckduckgo.com'
DUCKDUCKGO_RE = r'^!(ddg|duckduckgo)\s+'
# DuckDuckGo Instance Answer function
# https://duckduckgo.com/api
def duckduckgo(bot, nick, query, channel):
params = {'q': query, 'format': 'json', 'no_html': 1, 'no_redirect': 1}
results = requests.get(DUCKDUCKGO_URL, params=params, timeout=bot.conn.requests_timeout)
/* ---------------------------- DuckDuckGo ---------------------------- */
function DuckDuckGo() {
}
DuckDuckGo.prototype.search = function( query, cloudback ) {
exec("curl 'http://api.duckduckgo.com/?format=json&q=" + escape( query ) + "'", function ( err, stdout, stderr ) {
var results = JSON.parse( stdout ) // What could possibly go wrong?
function register( j ) {
var ddg = new DuckDuckGo()
# select Op
@op = Op.where(:comment_karma => 0, :wikipedia_hits => 0).first
if url
require 'api/stats.grok.se'
#update Reddit users link and comment karma
require 'api/reddit.com'
link_karma = 0
comment_karma = 0
link_karma += json["data"]["link_karma"].to_i
comment_karma += json["data"]["comment_karma"].to_i
user.update_attributes(:link_karma => json["data"]["link_karma"], :comment_karma => json["data"]["comment_karma"])
end
task :tag => :environment do
require 'api/duckduckgo.com'
Copyright 2013, Edward Powell (embolalia.net)
Copyright 2008-2013 Sean B. Palmer (inamidst.com)
More info:
* jenni: https://github.com/myano/jenni/
* Phenny: http://inamidst.com/phenny/
"""
r_tag = re.compile(r'<(?!!)[^>]+>')
web.urllib.URLopener.__init__(self, *args)
self.addheader('Referer', 'https://github.com/myano/jenni')
query = query.encode('utf-8')
uri = 'https://ajax.googleapis.com/ajax/services/search/web'
r_bing = re.compile(r'<h3><a href="([^"]+)"')
query = web.urllib.quote(query)
base = 'http://www.bing.com/search?mkt=%s&q=' % lang
// DuckDuckGo Zero-click API client. See https://duckduckgo.com/api.html
// for information about the API.
//
// Example command-line program to show abstracts:
// "fmt"
// "github.com/whee/ddg"
// BaseURL specifies where to send API requests. If zero-value,
// "api.duckduckgo.com" is used.
BaseURL string
// ZeroClick queries DuckDuckGo's zero-click API for the specified query
// ZeroClick queries DuckDuckGo's zero-click API for the specified query
if c.BaseURL == "" {
c.BaseURL = "api.duckduckgo.com"
# Author:: Tom Gilbert (giblet) <tom@linuxbrit.co.uk>
# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
GOOGLE_SEARCH = "http://www.google.com/search?oe=UTF-8&q="
GOOGLE_WAP_SEARCH = "http://www.google.com/m/search?hl=en&q="
GOOGLE_WAP_LINK = /"r">(?:<div[^>]*>)?<a href="([^"]+)"[^>]*>(.*?)<\/a>/im
DDG_API_SEARCH = "http://api.duckduckgo.com/?format=xml&no_html=1&skip_disambig=1&no_redirect=0&q="
WOLFRAM_API_SEARCH = "http://api.wolframalpha.com/v2/query?input=%{terms}&appid=%{key}&format=plaintext" +
"&excludepodid=SeriesRepresentations:*"
WOLFRAM_API_KEY = "4EU37Y-TX9WJG3JH3"
class SearchPlugin < Plugin
Config.register Config::IntegerValue.new('duckduckgo.hits',
:desc => "Number of hits to return from searches")
Config.register Config::IntegerValue.new('duckduckgo.first_par',
my %links = (
# duckduckgo.com/*.html / etc.
"goodie" => "https://duckduckgo.com/goodies.html",
"bang" => "https://duckduckgo.com/bang.html",
"newbang" => "https://duckduckgo.com/newbang.html",
"about" => "https://duckduckgo.com/about.html",
"setting" => "https://duckduckgo.com/settings.html",
"param" => "https://duckduckgo.com/params.html",
"privacy" => "https://duckduckgo.com/privacy.html",
"feedback" => "https://duckduckgo.com/feedback.html",
"spread" => "https://duckduckgo.com/spread.html",
"traffic" => "https://duckduckgo.com/traffic.html",
"searchbox" => "https://duckduckgo.com/search_box.html",
"api" => "https://api.duckduckgo.com/",
"homepage" => "https://duckduckgo.com/",
# Author:: Tom Gilbert (giblet) <tom@linuxbrit.co.uk>
# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
GOOGLE_SEARCH = "http://www.google.com/search?oe=UTF-8&q="
GOOGLE_WAP_SEARCH = "http://www.google.com/m/search?hl=en&q="
GOOGLE_WAP_LINK = /"r">(?:<div[^>]*>)?<a href="([^"]+)"[^>]*>(.*?)<\/a>/im
DDG_API_SEARCH = "http://api.duckduckgo.com/?format=xml&no_html=1&skip_disambig=1&no_redirect=0&q="
WOLFRAM_API_SEARCH = "http://api.wolframalpha.com/v2/query?input=%{terms}&appid=%{key}&format=plaintext" +
"&excludepodid=SeriesRepresentations:*"
WOLFRAM_API_KEY = "4EU37Y-TX9WJG3JH3"
class SearchPlugin < Plugin
Config.register Config::IntegerValue.new('duckduckgo.hits',
:desc => "Number of hits to return from searches")
Config.register Config::IntegerValue.new('duckduckgo.first_par',
# Author:: Tom Gilbert (giblet) <tom@linuxbrit.co.uk>
# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
GOOGLE_SEARCH = "http://www.google.com/search?oe=UTF-8&q="
GOOGLE_WAP_SEARCH = "http://www.google.com/m/search?hl=en&q="
GOOGLE_WAP_LINK = /"r">(?:<div[^>]*>)?<a href="([^"]+)"[^>]*>(.*?)<\/a>/im
DDG_API_SEARCH = "http://api.duckduckgo.com/?format=xml&no_html=1&skip_disambig=1&no_redirect=0&q="
WOLFRAM_API_SEARCH = "http://api.wolframalpha.com/v2/query?input=%{terms}&appid=%{key}&format=plaintext"
"&excludepodid=SeriesRepresentations:*"
WOLFRAM_API_KEY = "4EU37Y-TX9WJG3JH3"
class SearchPlugin < Plugin
Config.register Config::IntegerValue.new('duckduckgo.hits',
:desc => "Number of hits to return from searches")
Config.register Config::IntegerValue.new('duckduckgo.first_par',
package App::DuckDuckGo::UI;
use Curses::UI::TextEditor;
use WWW::DuckDuckGo;
use JSON;
use POE 'Component::Client::HTTP';
use App::DuckDuckGo::UI::Config;
is => 'ro',
default => sub { App::DuckDuckGo::UI::Config->new },
_start => sub {
$_[HEAP]->{ua} = POE::Component::Client::HTTP->spawn(Alias => 'ua', Timeout => 20, FollowRedirects => 1);
sub autocomplete_and_add {
my ($self, $call) = @_;
my $request = HTTP::Request->new(GET => "https://api.duckduckgo.com/$call");
#
# This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
# This is free software, and you are welcome to redistribute it
# under certain conditions; type `show c' for details.
class ddg(object):
"""DuckDuckGo search tools. Currently just 0-click info."""
self.server = server
self.commands = ["ddg"]
self.server.handle("command", self.handle_command, self.commands)
def handle_command(self, channel, user, cmd, args):
if len(args) < 1:
self.server.doMessage(channel, user+": DuckDuckGo.com Zero-Click infoboxes search. Syntax: ddg <query>.")
request = "+".join(args)
sock = urllib.request.urlopen("http://api.duckduckgo.com/?q=%s&o=json" % request)
search.py - Willie Web Search Module
Copyright 2008-9, Sean B. Palmer, inamidst.com
query = query.encode('utf-8')
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
def formatnumber(n):
"""Format a number with beautiful commas."""
else: willie.reply("No results found for '%s'." % query)
g.commands = ['g','google']
willie.say(query + ': ' + num)
gc.commands = ['gc']
else: willie.reply("No results found for '%s'." % query)
bing.commands = ['bing']
r_duck = re.compile(r'nofollow" class="[^"]+" href="(.*?)">')
query = web.quote(query)
uri = 'http://duckduckgo.com/html/?q=%s&kl=uk-en' % query
Copyright 2013, Edward Powell (embolalia.net)
Copyright 2008-2013 Sean B. Palmer (inamidst.com)
More info:
* jenni: https://github.com/myano/jenni/
* Phenny: http://inamidst.com/phenny/
"""
r_tag = re.compile(r'<(?!!)[^>]+>')
query = query.encode('utf-8')
uri = 'https://ajax.googleapis.com/ajax/services/search/web'
jenni.say(reply)
gcs.commands = ['gcs', 'comp']
r_bing = re.compile(r'<h3><a href="([^"]+)"')
query = web.urllib.quote(query)
base = 'http://www.bing.com/search?mkt=%s&q=' % lang
Copyright 2009-2013, Michael Yanovich (yanovich.net)
Copyright 2008-2013, Sean B. Palmer (inamidst.com)
More info:
* jenni: https://github.com/myano/jenni/
* Phenny: http://inamidst.com/phenny/
"""
c_pattern = r'(?ims)<(?:h2 class="r"|div id="aoba")[^>]*>(.*?)</(?:h2|div)>'
c_answer = re.compile(c_pattern)
r_tag = re.compile(r'<(?!!)[^>]+>')
if attempt_two:
new_url = 'https://duckduckgo.com/html/?q=%s&kl=us-en&kp=-1' % (web.urllib.quote(q))
else:
#### Attempt #3 (DuckDuckGo's API)
ddg_uri = 'https://api.duckduckgo.com/?format=json&q='
ddg_uri += urllib.quote(q)
#
# Commands:
robot.respond /(abs|abstract) (.+)/i, (res) ->
abstract_url = "http://api.duckduckgo.com/?format=json&q=#{encodeURIComponent(res.match[2])}"
# Astronomy is the scientific study of celestial objects.
# http://duckduckgo.com/Astronomy
# contumacious definition: stubbornly disobedient.
# http://merriam-webster.com/dictionary/contumacious
search.py - Willie Web Search Module
Copyright 2008-9, Sean B. Palmer, inamidst.com
from willie import web
from willie.module import commands, example
"""Search using AjaxSearch, and return its JSON."""
uri = 'http://ajax.googleapis.com/ajax/services/search/web'
def formatnumber(n):
"""Format a number with beautiful commas."""
@commands('g', 'google')
@commands('gc')
r_query = re.compile(
query = query.replace('!', '')
uri = 'http://duckduckgo.com/html/?q=%s&kl=uk-en' % query