Skip to content

Commit b306aa9

Browse files
committed
Added meanings option
This commit adds ability to query just for meanings of queries. Example: http://api.duckduckgo.com/?q=apple&format=json&pretty=1&d=0 vs. http://api.duckduckgo.com/?q=apple&format=json&pretty=1&d=1
1 parent 3abd21c commit b306aa9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

duckduckgo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__version__ = 0.2
77

88

9-
def query(query, useragent='python-duckduckgo '+str(__version__), safesearch=True, html=False, **kwargs):
9+
def query(query, useragent='python-duckduckgo '+str(__version__), safesearch=True, html=False, meanings=True, **kwargs):
1010
"""
1111
Query DuckDuckGo, returning a Results object.
1212
@@ -24,17 +24,20 @@ def query(query, useragent='python-duckduckgo '+str(__version__), safesearch=Tru
2424
useragent: UserAgent to use while querying. Default: "python-duckduckgo %d" (str)
2525
safesearch: True for on, False for off. Default: True (bool)
2626
html: True to allow HTML in output. Default: False (bool)
27+
meanings: True to include disambiguations in results (bool)
2728
Any other keyword arguments are passed directly to DuckDuckGo as URL params.
2829
""" % __version__
2930

3031
safesearch = '1' if safesearch else '-1'
3132
html = '0' if html else '1'
33+
meanings = '1' if meanings else '0'
3234
params = {
3335
'q': query,
3436
'o': 'json',
3537
'kp': safesearch,
3638
'no_redirect': '1',
3739
'no_html': html,
40+
'd': meanings,
3841
}
3942
params.update(kwargs)
4043
encparams = urllib.urlencode(params)

0 commit comments

Comments
 (0)