DuckDuckGo Plugin #9

Merged
merged 8 commits into from Jan 31, 2017

Conversation

Projects
None yet
2 participants
Contributor

paddatrapper commented Jun 27, 2016

Created a DuckDuckGo Instant Answer query plugin. Also fixed the DB connection to work with newer versions of sqlalchemy.

.gitignore
+/build/
+/Ibid.egg-info/
+/dist/
+/bothome/
@paddatrapper

paddatrapper Sep 7, 2016

Contributor

As in put them in alphabetical order?

ibid/db/types.py
@@ -8,28 +8,28 @@
def monkey_patch():
import sqlalchemy.dialects.postgresql
sqlalchemy.dialects.postgresql.dialect.ischema_names['citext'] = IbidUnicodeText
- def postgres_visit_IBID_VARCHAR(self, type_):
+ def postgres_visit_IBID_VARCHAR(self, type_, **kw):
if type_.case_insensitive:
return 'CITEXT'
else:
return self.visit_VARCHAR(type_)
@stefanor

stefanor Aug 20, 2016

Owner

Shouldn't we be passing through the **kw here?

ibid/plugins/ddg.py
@@ -0,0 +1,66 @@
+# Copyright (c) 2008-2011, Michael Gorven, Stefano Rivera
@stefanor

stefanor Aug 20, 2016

Owner

Take some credit :) This should be 2016, paddatrapper

ibid/plugins/ddg.py
+}}
+
+default_user_agent = 'Mozilla/5.0'
+default_referer = "http://ibid.omnia.za.net/"
@stefanor

stefanor Aug 20, 2016

Owner

Stick to one quote style for the whole file. Single quotes tend to be preferred.

ibid/plugins/ddg.py
+ params['gl'] = country
+
+ headers = {'referer': self.referer}
+ return json_webservice('http://api.duckduckgo.com', params, headers)
@stefanor

stefanor Aug 20, 2016

Owner

No https? :(

ibid/plugins/ddg.py
+ headers = {'referer': self.referer}
+ return json_webservice('http://api.duckduckgo.com', params, headers)
+
+ @match(r'^(ddg|duckduckgo(?:\.com?))?(?:\.([a-z]{2}))?\s+(?:for\s+)?(.+?)$')
@stefanor

stefanor Aug 20, 2016

Owner

err the ddg | duckduckgo bit is optional?

ibid/plugins/ddg.py
+ topic = "Results"
+ for item in items[topic]:
+ title = item['Text']
+ results.append(u'"%s" %s' % (decode_htmlentities(title), item['FirstURL']))
@stefanor

stefanor Aug 20, 2016

Owner

The API response is HTML encoded? o_O

ibid/plugins/ddg.py
+ topic = "RelatedTopics"
+ for i in range(5):
+ if i >= len(items[topic]):
+ break
@stefanor

stefanor Aug 20, 2016

Owner

for i in range(max(5, len(items[topic]))) ?

ibid/plugins/ddg.py
+ break
+ try:
+ title = items[topic][i]['Text']
+ results.append(u'%s' % (decode_htmlentities(title)))
@stefanor

stefanor Aug 20, 2016

Owner

The string substitution doesn't seem to be doing anything useful

ibid/plugins/ddg.py
+ title = items[topic][i]['Text']
+ results.append(u'%s' % (decode_htmlentities(title)))
+ except KeyError:
+ pass
@stefanor

stefanor Aug 20, 2016

Owner

Why wolud that happen?

ibid/plugins/ddg.py
+ if country is not None:
+ params['gl'] = country
+
+ headers = {'referer': self.referer}
@stefanor

stefanor Aug 20, 2016

Owner

Do they actually require a referer header?

Contributor

paddatrapper commented Dec 10, 2016

All issues corrected

@stefanor stefanor merged commit f539c21 into ibid:master Jan 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment