Simple client library for the webhose.io REST API
A simple way to access the webhose.io API from your Python code
import webhose webhose.config(token=YOUR_API_KEY) for post in webhose.search("github"): print(post.title)
To make use of the webhose.io API, you need to obtain a token that would be used on every request. To obtain an API key, create an account at https://webhose.io/auth/signup, and then go into https://webhose.io/dashboard to see your token.
You can install from source:
$ git clone https://github.com/Buzzilla/webhose-python $ cd webhose-python $ python setup.py install
To get started, you need to import the library, and set your access token. (Replace YOUR_API_KEY with your actual API key).
>>> import webhose >>> webhose.config(token=YOUR_API_KEY)
Now you can make a request and inspect the results:
>>> r = webhose.search("foobar") >>> r.total 62 >>> len(r.posts) 62 >>> r.posts.language 'english' >>> r.posts.title 'Putting quotes around dictionary keys in JS'
For your convenience, the Response object is iterable, so you can loop over it and get all the results. The iterator will create additional API requests to fetch additional pages.
>>> total_words = 0 >>> for post in r: ... total_words += len(post.text.split(" ")) ... >>> print(total_words) 56006
Warning: This method can use up your credits if your search has lots of results.
Query object correspond to the advanced search options that appear on https://webhose.io/use
Query object have the following members:
Query objects implement the __str__() method, which shows the resulting search string.
Response objects have the following members:
Response objects implement the __iter__() method, which can be used to loop over all posts matching the query. (Automatic page fetching)
Post and Thread object contain the actual data returned from the API. Consult https://webhose.io/documentation to find out about their structure.
If you want to make repeated searches, performing an action whenever there are new results, use code like this:
r = webhose.search("skyrim") while True: for post in r: perform_action(post) time.sleep(300) r = r.get_next()