Skip to content

Commit abd3768

Browse files
committed
Added test for new function (closes issue #9)
1 parent cfb4c61 commit abd3768

File tree

1 file changed

+53
-23
lines changed

1 file changed

+53
-23
lines changed

docs/TwitterSearch.rst

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,31 @@ If you're looking for the exceptions thrown by this class based on the HTTP stat
88
Available methods
99
-----------------
1010

11-
============================================== ====================================================================================================================================================================================================== ================================================================================================================
12-
Method Description Example
13-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
14-
``setProxy(<dict>)`` Sets a proxy. Because only HTTPS requests are done, it's sufficient to only input a dict containing a ``https`` entry ``setProxy({'https':'10.0.0.1:123'})``
15-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
16-
``authenticate(verify=<boolean>)`` Creates an authenticated oauth2 client and if ``verify`` is true, it also checkes if the user credentials are valid. The **default** value is *True* ``authenticate()``, ``authenticate(True)``
17-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
18-
``searchTweetsIterable(<TwitterSearchOrder>)`` Queries the Twitter API, iterates through tweets and reloads available older tweets automatically see `Basic usage <basic_usage.html>`_
19-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
20-
``searchTweets(<TwitterSearchOrder>)`` Queries the Twitter API **without** iterating or reloading of further results and returns response see `Advanced usage`_
21-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
22-
``sentSearch(<string>)`` Queries the Twitter Search API with a given query string and returns response ``sentSearch('?q=One+Two&count=100')``
23-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
24-
``searchNextResults()`` Queries the API for more tweets and returns response see `Advanced usage`_
25-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
26-
``getMetadata()`` Returns a dict of meta information about the last query see `Advanced usage`_
27-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
28-
``getTweets()`` Returns a dict of all tweets returned by last query see `Advanced usage`_
29-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
30-
``getStatistics()`` Returns a dict of the type ``{ 'queries' : <int>, 'tweets' : <int> }`` with statistical values about the number of queries and the sum of all tweets recieved by this very instance of *TwitterSearch* ``print "Queries done %i / Tweets received %i" % (ts.getStatistics()['queries'], ts.getStatistics()['tweets'])``
31-
---------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
32-
``checkHTTPStatus(<int>)`` Checks if given HTTP status code is in ``TwitterSearch.exceptions`` and raises ``TwitterSearchException`` if this is the case ``checkHTTPStatus(200)``, ``checkHTTPStatus(401)``
33-
============================================== ====================================================================================================================================================================================================== ================================================================================================================
11+
=============================================== ====================================================================================================================================================================================================== ================================================================================================================
12+
Method Description Example
13+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
14+
``setProxy(<dict>)`` Sets a proxy. Because only HTTPS requests are done, it's sufficient to only input a dict containing a ``https`` entry ``setProxy({'https':'10.0.0.1:123'})``
15+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
16+
``authenticate(verify=<boolean>)`` Creates an authenticated oauth2 client and if ``verify`` is true, it also checkes if the user credentials are valid. The **default** value is *True* ``authenticate()``, ``authenticate(True)``
17+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
18+
``searchTweetsIterable(<TwitterSearchOrder>)`` Queries the Twitter API, iterates through tweets and reloads available older tweets automatically see `Basic usage <basic_usage.html>`_
19+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
20+
``searchTweets(<TwitterSearchOrder>)`` Queries the Twitter API **without** iterating or reloading of further results and returns response see `Advanced usage`_
21+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
22+
``sentSearch(<string>)`` Queries the Twitter Search API with a given query string and returns response ``sentSearch('?q=One+Two&count=100')``
23+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
24+
``searchNextResults()`` Queries the API for more tweets and returns response see `Advanced usage`_
25+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
26+
``getMetadata()`` Returns a dict of meta information about the last query see `Advanced usage`_
27+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
28+
``getTweets()`` Returns a dict of all tweets returned by last query see `Advanced usage`_
29+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
30+
``getStatistics()`` Returns a dict of the type ``{ 'queries' : <int>, 'tweets' : <int> }`` with statistical values about the number of queries and the sum of all tweets recieved by this very instance of *TwitterSearch* ``print "Queries done %i / Tweets received %i" % (ts.getStatistics()['queries'], ts.getStatistics()['tweets'])``
31+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
32+
``checkHTTPStatus(<int>)`` Checks if given HTTP status code is in ``TwitterSearch.exceptions`` and raises ``TwitterSearchException`` if this is the case ``checkHTTPStatus(200)``, ``checkHTTPStatus(401)``
33+
----------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------------------------------------
34+
``setSupportedLanguages(<TwitterSearchOrder>)`` Loads currently supported languages from Twitter and stores them in a ``TwitterSearchOrder`` instance see `Advanced usage`_
35+
=============================================== ====================================================================================================================================================================================================== ================================================================================================================
3436

3537
The methods ``next()``, ``__next__()`` and ``__iter__()`` are used during the iteration process. For more information about those methods please consult the `official Python documentation <http://docs.python.org/2/library/stdtypes.html#iterator-types>`_.
3638

@@ -281,3 +283,31 @@ A possible solution could look like this:
281283
except TwitterSearchException as e:
282284
print(e)
283285
286+
On-the-fly loading of supported languages
287+
+++++++++++++++++++++++++++++++++++++++++
288+
289+
As you may have figured out some languages are not supported by Twitter and those that are may change over time. This is why Twitter does provide `an endpoint <https://dev.twitter.com/docs/api/1.1/get/help/languages>`_ to load all currently supported languages. You may query it to gather current information about the languages in Twitter.
290+
291+
292+
.. code-block:: python
293+
294+
from TwitterSearch import *
295+
296+
try:
297+
tso = TwitterSearchOrder()
298+
ts = TwitterSearch('aaabbb', 'cccddd', '111222', '333444')
299+
300+
# load currently supported languages by Twitter and store them in a TwitterSearchOrder object
301+
ts.setSupportedLanguages(tso)
302+
303+
# try to set German (see ISO 639-1) as language
304+
ts.setLanguage('de')
305+
print('German seems to be officially supported by Twitter. Yay!')
306+
307+
except TwitterSearchException as e:
308+
309+
# if we get an 1002 code it means that 'de' is not supported (see TwitterSearchException)
310+
if e.code == 1002:
311+
print('Oh no - German is not supported :(')
312+
print(e)
313+

0 commit comments

Comments
 (0)