From 789787b8669ea83d1baf6b54ed3c604527632b52 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 25 Apr 2019 20:18:13 +0100 Subject: [PATCH] Add duckduckgo.py --- modules/duckduckgo.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 modules/duckduckgo.py diff --git a/modules/duckduckgo.py b/modules/duckduckgo.py new file mode 100644 index 00000000..445efb5c --- /dev/null +++ b/modules/duckduckgo.py @@ -0,0 +1,24 @@ +from src import ModuleManager, utils + +URL_DDG = "https://api.duckduckgo.com" + +class Module(ModuleManager.BaseModule): + _name = "DDG" + + @utils.hook("received.command.ddg", min_args=1) + def duckduckgo(self, event): + """ + :help: Get first Google result for a given search term + :usage: [search term] + """ + + phrase = event["args"] or event["target"].buffer.get() + if phrase: + page = utils.http.request(URL_DDG, get_params={ + "q": phrase, "format": "json", "no_html": "1", + "no_redirect": "1"}, json=True) + + if page: + event["stdout"].write(page.data["AbstractURL"]) + else: + event["stderr"].write("No results found")