Skip to content

Commit

Permalink
Fix #105: Ignore instant result in JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
jarun committed Feb 3, 2020
1 parent efffb62 commit 6b33a52
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ddgr
Original file line number Diff line number Diff line change
Expand Up @@ -1381,11 +1381,16 @@ class DdgCmd:
return self._ddg_url.keywords

@require_keywords
def fetch(self):
def fetch(self, json_output=False):
"""Fetch a page and parse for results.
Results are stored in ``self.results``.
Parameters
----------
json_output : bool, optional
Whether to dump results in JSON format. Default is False.
Raises
------
DDGConnectionError
Expand Down Expand Up @@ -1429,7 +1434,7 @@ class DdgCmd:
self._ddg_url.np_next = parser.np_next_button

# Show instant answer
if self.index == 0 and parser.click_result:
if self.index == 0 and parser.click_result and not json_output:
if self.colors:
print(self.colors.abstract)

Expand Down Expand Up @@ -2056,7 +2061,7 @@ def main():
# Handle bangs
open_url(repl._ddg_url.full())
else:
repl.fetch()
repl.fetch(opts.json)
if opts.ducky:
if repl.results:
open_url(repl.results[0].url)
Expand Down

0 comments on commit 6b33a52

Please sign in to comment.