Skip to content

Commit 235f595

Browse files
author
Aaron Gonzales
committed
updated readme
1 parent 0b3bca2 commit 235f595

3 files changed

Lines changed: 57 additions & 61 deletions

File tree

README.rst

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Python Twitter Search API
22
=========================
33

4-
This library serves as a python interface to the `Twitter premium and
4+
This library serves as a Python interface to the `Twitter premium and
55
enterprise search
6-
APIs <https://developer.twitter.com/en/docs/tweets/search/overview/30-day-search>`__.
7-
It provides a command-line utility and a library usable from within
8-
python. It comes with tools for assisting in dynamic generation of
9-
search rules and for parsing tweets.
6+
APIs <https://developer.twitter.com/en/docs/tweets/search/overview/>`__.
7+
It provides a command-line utility and a library usable from within a
8+
Python program. It comes with tools for assisting in dynamic generation
9+
of search rules and for parsing tweets.
1010

1111
Pretty docs can be seen
1212
`here <https://twitterdev.github.io/search_tweets_api/>`__.
@@ -47,9 +47,10 @@ Or you can install the development version locally via
4747
Credential Handling
4848
===================
4949

50-
The premium and enterprise Search APIs use different credentials and we
51-
attempt to provide methods of seamless handling for all customers. We
52-
support YAML-file based methods and environment variables for access.
50+
The premium and enterprise Search APIs use different authentication
51+
methods and we attempt to provide a seamless way to handle
52+
authentication for all customers. We support both YAML-file based
53+
methods and environment variables for access.
5354

5455
A YAML credential file should look like this:
5556

@@ -68,7 +69,7 @@ fields; Enterprise clients require ``username``, ``password``, and
6869
discern the account type and declare a warning about this behavior. The
6970
``load_credentials`` function also allows ``account_type`` to be set.
7071

71-
Our credential reader will default this file being located at
72+
Our credential reader will look for this file at
7273
``"~/.twitter_keys.yaml"``, but you can pass the relevant location as
7374
needed. You can also specify a different key in the yaml file, which can
7475
be useful if you have different endpoints, e.g., ``dev``, ``test``,
@@ -109,7 +110,6 @@ command line app and Python library.
109110
.. code:: python
110111
111112
from searchtweets import load_credentials
112-
import os
113113
114114
.. code:: python
115115
@@ -138,10 +138,11 @@ Environment Variable Overrides
138138
------------------------------
139139

140140
If we set our environment variables, the program will look for them
141-
regardless of a YAML file's validity or existence.
141+
regardless of a YAML files validity or existence.
142142

143143
.. code:: python
144144
145+
import os
145146
os.environ["SEARCHTWEETS_USERNAME"] = "ENV_USERNAME"
146147
os.environ["SEARCHTWEETS_PASSWORD"] = "ENV_PW"
147148
os.environ["SEARCHTWEETS_ENDPOINT"] = "https://endpoint"
@@ -201,7 +202,6 @@ environment variables.
201202
.. code:: bash
202203
203204
python search_tweets.py \
204-
--endpoint <MY_ENDPOINT> \
205205
--max-results 100 \
206206
--results-per-call 100 \
207207
--filter-rule "beyonce has:hashtags" \
@@ -333,12 +333,7 @@ Full options are listed below:
333333

334334
--------------
335335

336-
Using the Twitter Search APIs Python Wrapper
337-
============================================
338-
339-
.. _using-the-twitter-search-apis-python-wrapper-1:
340-
341-
Using the Twitter Search APIs Python Wrapper
336+
Using the Twitter Search APIs' Python Wrapper
342337
============================================
343338

344339
Working with the API within a Python program is straightforward both for
@@ -371,12 +366,12 @@ Premium Setup
371366
372367
There is a function that formats search API rules into valid json
373368
queries called ``gen_rule_payload``. It has sensible defaults, such as
374-
pulling more tweets per call than the default 100 (but note that a
369+
pulling more Tweets per call than the default 100 (but note that a
375370
sandbox environment can only have a max of 100 here, so if you get
376371
errors, please check this) not including dates, and defaulting to hourly
377372
counts when using the counts api. Discussing the finer points of
378373
generating search rules is out of scope for these examples; I encourage
379-
you to see the docs to learn the nuances within, but for now let's see
374+
you to see the docs to learn the nuances within, but for now lets see
380375
what a rule looks like.
381376

382377
.. code:: python
@@ -391,30 +386,30 @@ what a rule looks like.
391386
This rule will match tweets that have the text ``beyonce`` in them.
392387

393388
From this point, there are two ways to interact with the API. There is a
394-
quick method to collect smaller amounts of tweets to memory that
389+
quick method to collect smaller amounts of Tweets to memory that
395390
requires less thought and knowledge, and interaction with the
396391
``ResultStream`` object which will be introduced later.
397392

398393
Fast Way
399394
--------
400395

401-
We'll use the ``search_args`` variable to power the configuration point
396+
Well use the ``search_args`` variable to power the configuration point
402397
for the API. The object also takes a valid PowerTrack rule and has
403-
options to cutoff search when hitting limits on both number of tweets
398+
options to cutoff search when hitting limits on both number of Tweets
404399
and API calls.
405400

406-
We'll be using the ``collect_results`` function, which has three
401+
Well be using the ``collect_results`` function, which has three
407402
parameters.
408403

409404
- rule: a valid PowerTrack rule, referenced earlier
410405
- max_results: as the API handles pagination, it will stop collecting
411406
when we get to this number
412-
- result_stream_args: configuration args that we've already specified.
407+
- result_stream_args: configuration args that weve already specified.
413408

414409
For the remaining examples, please change the args to either premium or
415410
enterprise depending on your usage.
416411

417-
Let's see how it goes:
412+
Lets see how it goes:
418413

419414
.. code:: python
420415
@@ -426,9 +421,9 @@ Let's see how it goes:
426421
max_results=100,
427422
result_stream_args=enterprise_search_args) # change this if you need to
428423
429-
By default, tweet payloads are lazily parsed into a ``Tweet`` object. An
430-
overwhelming number of tweet attributes are made available directly, as
431-
such:
424+
By default, Tweet payloads are lazily parsed into a ``Tweet``
425+
`object <https://twitterdev.github.io/tweet_parser/>`__. An overwhelming
426+
number of Tweet attributes are made available directly, as such:
432427

433428
.. code:: python
434429
@@ -492,9 +487,9 @@ such:
492487
Airtime Pro
493488
Twitter for iPhone
494489

495-
Voila, we have some tweets. For interactive environments and other cases
496-
where you don't care about collecting your data in a single load or
497-
don't need to operate on the stream of tweets or counts directly, I
490+
Voila, we have some Tweets. For interactive environments and other cases
491+
where you dont care about collecting your data in a single load or
492+
dont need to operate on the stream of Tweets or counts directly, I
498493
recommend using this convenience function.
499494

500495
Working with the ResultStream
@@ -529,14 +524,15 @@ stop on number of pages to limit your API call usage.
529524

530525
There is a function, ``.stream``, that seamlessly handles requests and
531526
pagination for a given query. It returns a generator, and to grab our
532-
500 tweets that mention ``beyonce`` we can do this:
527+
500 Tweets that mention ``beyonce`` we can do this:
533528

534529
.. code:: python
535530
536531
tweets = list(rs.stream())
537532
538-
Tweets are lazily parsed using our Tweet Parser, so tweet data is very
539-
easily extractable.
533+
Tweets are lazily parsed using our `Tweet
534+
Parser <https://twitterdev.github.io/tweet_parser/>`__, so tweet data is
535+
very easily extractable.
540536

541537
.. code:: python
542538
@@ -561,14 +557,14 @@ easily extractable.
561557
Counts Endpoint
562558
---------------
563559

564-
We can also use the Search API Counts endpoint to get counts of tweets
560+
We can also use the Search API Counts endpoint to get counts of Tweets
565561
that match our rule. Each request will return up to *30* results, and
566562
each count request can be done on a minutely, hourly, or daily basis.
567563
The underlying ``ResultStream`` object will handle converting your
568564
endpoint to the count endpoint, and you have to specify the
569565
``count_bucket`` argument when making a rule to use it.
570566

571-
The process is very similar to grabbing tweets, but has some minor
567+
The process is very similar to grabbing Tweets, but has some minor
572568
differences.
573569

574570
*Caveat - premium sandbox environments do NOT have access to the Search
@@ -623,7 +619,7 @@ Our results are pretty straightforward and can be rapidly used.
623619
Dated searches / Full Archive Search
624620
------------------------------------
625621

626-
Let's make a new rule and pass it dates this time.
622+
Lets make a new rule and pass it dates this time.
627623

628624
``gen_rule_payload`` takes dates of the forms ``YYYY-mm-DD`` and
629625
``YYYYmmDD``.
@@ -651,7 +647,6 @@ method; please see your developer console for details.
651647
652648
.. code:: python
653649
654-
# usiing unidecode only to
655650
[print(tweet.all_text) for tweet in tweets[0:10]];
656651
657652
::

examples/api_example.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"cell_type": "markdown",
6565
"metadata": {},
6666
"source": [
67-
"There is a function that formats search API rules into valid json queries called `gen_rule_payload`. It has sensible defaults, such as pulling more tweets per call than the default 100 (but note that a sandbox environment can only have a max of 100 here, so if you get errors, please check this) not including dates, and defaulting to hourly counts when using the counts api. Discussing the finer points of generating search rules is out of scope for these examples; I encourage you to see the docs to learn the nuances within, but for now let's see what a rule looks like."
67+
"There is a function that formats search API rules into valid json queries called `gen_rule_payload`. It has sensible defaults, such as pulling more Tweets per call than the default 100 (but note that a sandbox environment can only have a max of 100 here, so if you get errors, please check this) not including dates, and defaulting to hourly counts when using the counts api. Discussing the finer points of generating search rules is out of scope for these examples; I encourage you to see the docs to learn the nuances within, but for now let's see what a rule looks like."
6868
]
6969
},
7070
{
@@ -96,12 +96,12 @@
9696
"cell_type": "markdown",
9797
"metadata": {},
9898
"source": [
99-
"From this point, there are two ways to interact with the API. There is a quick method to collect smaller amounts of tweets to memory that requires less thought and knowledge, and interaction with the `ResultStream` object which will be introduced later.\n",
99+
"From this point, there are two ways to interact with the API. There is a quick method to collect smaller amounts of Tweets to memory that requires less thought and knowledge, and interaction with the `ResultStream` object which will be introduced later.\n",
100100
"\n",
101101
"\n",
102102
"## Fast Way\n",
103103
"\n",
104-
"We'll use the `search_args` variable to power the configuration point for the API. The object also takes a valid PowerTrack rule and has options to cutoff search when hitting limits on both number of tweets and API calls.\n",
104+
"We'll use the `search_args` variable to power the configuration point for the API. The object also takes a valid PowerTrack rule and has options to cutoff search when hitting limits on both number of Tweets and API calls.\n",
105105
"\n",
106106
"We'll be using the `collect_results` function, which has three parameters.\n",
107107
"\n",
@@ -144,7 +144,7 @@
144144
"cell_type": "markdown",
145145
"metadata": {},
146146
"source": [
147-
"By default, tweet payloads are lazily parsed into a `Tweet` object. An overwhelming number of tweet attributes are made available directly, as such:"
147+
"By default, Tweet payloads are lazily parsed into a `Tweet` [object](https://twitterdev.github.io/tweet_parser/). An overwhelming number of Tweet attributes are made available directly, as such:"
148148
]
149149
},
150150
{
@@ -241,7 +241,7 @@
241241
"cell_type": "markdown",
242242
"metadata": {},
243243
"source": [
244-
"Voila, we have some tweets. For interactive environments and other cases where you don't care about collecting your data in a single load or don't need to operate on the stream of tweets or counts directly, I recommend using this convenience function.\n",
244+
"Voila, we have some Tweets. For interactive environments and other cases where you don't care about collecting your data in a single load or don't need to operate on the stream of Tweets or counts directly, I recommend using this convenience function.\n",
245245
"\n",
246246
"\n",
247247
"## Working with the ResultStream\n",
@@ -285,7 +285,7 @@
285285
"cell_type": "markdown",
286286
"metadata": {},
287287
"source": [
288-
"There is a function, `.stream`, that seamlessly handles requests and pagination for a given query. It returns a generator, and to grab our 500 tweets that mention `beyonce` we can do this:"
288+
"There is a function, `.stream`, that seamlessly handles requests and pagination for a given query. It returns a generator, and to grab our 500 Tweets that mention `beyonce` we can do this:"
289289
]
290290
},
291291
{
@@ -303,7 +303,7 @@
303303
"cell_type": "markdown",
304304
"metadata": {},
305305
"source": [
306-
"Tweets are lazily parsed using our Tweet Parser, so tweet data is very easily extractable."
306+
"Tweets are lazily parsed using our [Tweet Parser](https://twitterdev.github.io/tweet_parser/), so tweet data is very easily extractable."
307307
]
308308
},
309309
{
@@ -341,9 +341,9 @@
341341
"source": [
342342
"## Counts Endpoint\n",
343343
"\n",
344-
"We can also use the Search API Counts endpoint to get counts of tweets that match our rule. Each request will return up to *30* results, and each count request can be done on a minutely, hourly, or daily basis. The underlying `ResultStream` object will handle converting your endpoint to the count endpoint, and you have to specify the `count_bucket` argument when making a rule to use it.\n",
344+
"We can also use the Search API Counts endpoint to get counts of Tweets that match our rule. Each request will return up to *30* results, and each count request can be done on a minutely, hourly, or daily basis. The underlying `ResultStream` object will handle converting your endpoint to the count endpoint, and you have to specify the `count_bucket` argument when making a rule to use it.\n",
345345
"\n",
346-
"The process is very similar to grabbing tweets, but has some minor differences.\n",
346+
"The process is very similar to grabbing Tweets, but has some minor differences.\n",
347347
"\n",
348348
"\n",
349349
"_Caveat - premium sandbox environments do NOT have access to the Search API counts endpoint._"

examples/api_example.rst

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Premium Setup
2929
3030
There is a function that formats search API rules into valid json
3131
queries called ``gen_rule_payload``. It has sensible defaults, such as
32-
pulling more tweets per call than the default 100 (but note that a
32+
pulling more Tweets per call than the default 100 (but note that a
3333
sandbox environment can only have a max of 100 here, so if you get
3434
errors, please check this) not including dates, and defaulting to hourly
3535
counts when using the counts api. Discussing the finer points of
@@ -51,7 +51,7 @@ what a rule looks like.
5151
This rule will match tweets that have the text ``beyonce`` in them.
5252

5353
From this point, there are two ways to interact with the API. There is a
54-
quick method to collect smaller amounts of tweets to memory that
54+
quick method to collect smaller amounts of Tweets to memory that
5555
requires less thought and knowledge, and interaction with the
5656
``ResultStream`` object which will be introduced later.
5757

@@ -60,7 +60,7 @@ Fast Way
6060

6161
We’ll use the ``search_args`` variable to power the configuration point
6262
for the API. The object also takes a valid PowerTrack rule and has
63-
options to cutoff search when hitting limits on both number of tweets
63+
options to cutoff search when hitting limits on both number of Tweets
6464
and API calls.
6565

6666
We’ll be using the ``collect_results`` function, which has three
@@ -86,9 +86,9 @@ Let’s see how it goes:
8686
max_results=100,
8787
result_stream_args=enterprise_search_args) # change this if you need to
8888
89-
By default, tweet payloads are lazily parsed into a ``Tweet`` object. An
90-
overwhelming number of tweet attributes are made available directly, as
91-
such:
89+
By default, Tweet payloads are lazily parsed into a ``Tweet``
90+
`object <https://twitterdev.github.io/tweet_parser/>`__. An overwhelming
91+
number of Tweet attributes are made available directly, as such:
9292

9393
.. code:: ipython3
9494
@@ -159,9 +159,9 @@ such:
159159
Twitter for iPhone
160160

161161

162-
Voila, we have some tweets. For interactive environments and other cases
162+
Voila, we have some Tweets. For interactive environments and other cases
163163
where you don’t care about collecting your data in a single load or
164-
don’t need to operate on the stream of tweets or counts directly, I
164+
don’t need to operate on the stream of Tweets or counts directly, I
165165
recommend using this convenience function.
166166

167167
Working with the ResultStream
@@ -198,14 +198,15 @@ stop on number of pages to limit your API call usage.
198198

199199
There is a function, ``.stream``, that seamlessly handles requests and
200200
pagination for a given query. It returns a generator, and to grab our
201-
500 tweets that mention ``beyonce`` we can do this:
201+
500 Tweets that mention ``beyonce`` we can do this:
202202

203203
.. code:: ipython3
204204
205205
tweets = list(rs.stream())
206206
207-
Tweets are lazily parsed using our Tweet Parser, so tweet data is very
208-
easily extractable.
207+
Tweets are lazily parsed using our `Tweet
208+
Parser <https://twitterdev.github.io/tweet_parser/>`__, so tweet data is
209+
very easily extractable.
209210

210211
.. code:: ipython3
211212
@@ -232,14 +233,14 @@ easily extractable.
232233
Counts Endpoint
233234
---------------
234235

235-
We can also use the Search API Counts endpoint to get counts of tweets
236+
We can also use the Search API Counts endpoint to get counts of Tweets
236237
that match our rule. Each request will return up to *30* results, and
237238
each count request can be done on a minutely, hourly, or daily basis.
238239
The underlying ``ResultStream`` object will handle converting your
239240
endpoint to the count endpoint, and you have to specify the
240241
``count_bucket`` argument when making a rule to use it.
241242

242-
The process is very similar to grabbing tweets, but has some minor
243+
The process is very similar to grabbing Tweets, but has some minor
243244
differences.
244245

245246
*Caveat - premium sandbox environments do NOT have access to the Search

0 commit comments

Comments
 (0)