Git Product home page Git Product logo

python-duckduckgo's Introduction

python-duckduckgo

A Python library for querying the Duck Duck Go API.

Copyright Michael Stephens <[email protected]>, released under a BSD-style license.

Source: http://github.com/mikejs/python-duckduckgo

Installation

To install run

python setup.py install

Usage

>>> import duckduckgo
>>> r = duckduckgo.query('Duck Duck Go')
>>> r.type
'answer'
>>> r.results[0].text
'Official site'
>>> r.results[0].url
'http://duckduckgo.com/'
>>> r.abstract.url
'http://en.wikipedia.org/wiki/Duck_Duck_Go'
>>> r.abstract.source
'Wikipedia'
>>> r = duckduckgo.query('Python')
>>> r.type
'disambiguation'
>>> r.related[6].text
'Python (programming language), a computer programming language'
>>> r.related[6].url
'http://duckduckgo.com/Python_(programming_language)'
>>> r = duckduckgo.query('1 + 1')
>>> r.type
'nothing'
>>> r.answer.text
'1 + 1 = 2'
>>> r.answer.type
'calc'

python-duckduckgo's People

Contributors

mikejs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

python-duckduckgo's Issues

Error: ValueError: No JSON object could be decoded

Dear mikejs,

I have the following problem, if I want to use the get_zci() method I get a random

Traceback (most recent call last):
  File "get-search-engine-hits.py", line 12, in <module>
    search_result = duckduckgo.get_zci(content)
  File "build/bdist.linux-x86_64/egg/duckduckgo.py", line 144, in get_zci
  File "build/bdist.linux-x86_64/egg/duckduckgo.py", line 55, in query
  File "/usr/lib64/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

message and afterwards I cannot use the library again because if the error shows up once, it ever shows up again (meaning even if I quit out of python interpreter and start a new session - the error persists). I found out that if I use the query method in between I can somehow reset this behaviour and then it works again. Here is the problematic code (I am not behind a proxy or firewall)

r-packages-debs.txt

acepack
ade4
annotate
AnnotationDbi
AnnotationHub
ape
assertthat
base64enc
BH
Biobase
BiocGenerics
BiocInstaller
BiocParallel
BiocStyle
biomaRt
Biostrings
biovizBase
bitops
broom
BSgenome
caTools
chron
coda
colorspace
corpcor
crayon
cubature
curl
data.table
DBI
DESeq2

problematic script

not_working.py

import duckduckgo,time
fname = "./r-packages-debs.txt"
with open(fname) as fp:
    for line in fp:
       content = line.strip() + " R"
       search_result = duckduckgo.get_zci(content)
       print content + "\t" + search_result
       time.sleep(5)

after running the screen and provoking the error for the first time, the error shows up every time you request something ever again until you use the query() method. This somehow "magically" resets the problem

introducing query() method avoids the problem completely

working.py

import duckduckgo,time
fname = "./r-packages-debs.txt"
with open(fname) as fp:
    for line in fp:
       # this "dummy request" avoids the problem but i dunno why
       duckduckgo.query("foo")
       content = line.strip() + " R"
       search_result = duckduckgo.get_zci(content)
       print content + "\t" + search_result
       time.sleep(5)

so somehow duckduckgo seems to save some information about former requests from the IP when using the get_zci() method or something is saved temporarily on the HDD somewhere.

Update the package to Python 3

You literaly just need to replace only one line !
This line:

import urllib2

Need to be replaced by this line:

import urllib.request as urllib2

If you want that Python2 and Python3 are supported, replace the import urllib2 line by:

import sys
if int(sys.version_info[0]) > 2:
    import urllib.request as urllib2
else:
    import urllib2

Please, change this in the code, then republish the package on PyPI.
Thanks !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.