Skip to content

Commit 07887ba

Browse files
author
Aaron Gonzales
committed
docstring updates and formatting
1 parent 81e5c70 commit 07887ba

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

searchtweets/api_utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@
5454
def convert_utc_time(datetime_str):
5555
"""
5656
Handles datetime argument conversion to the GNIP API format, which is
57-
`YYYYMMDDHHSS`. Flexible passing of date formats.
57+
`YYYYMMDDHHSS`. Flexible passing of date formats in the following types::
58+
59+
- YYYYmmDDHHMM
60+
- YYYY-mm-DD
61+
- YYYY-mm-DD HH:MM
62+
- YYYY-mm-DDTHH:MM
5863
5964
Args:
60-
datetime_str (str): the datestring, which can either be in GNIP API
61-
Format (YYYYmmDDHHSS), ISO date format (YYYY-mm-DD), ISO datetime
62-
format (YYYY-mm-DD HH:mm),
63-
or command-line ISO format (YYYY-mm-DDTHH:mm)
65+
datetime_str (str): valid formats are listed above.
6466
6567
Returns:
6668
string of GNIP API formatted date.

searchtweets/result_stream.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Licensed under the MIT License
44
# https://opensource.org/licenses/MIT
55
"""
6-
This module contains the request handing and actual api wrapping functionality.
6+
This module contains the request handing and actual API wrapping functionality.
77
8-
It's core method is the ``ResultStream`` object, which takes the API call
8+
Its core method is the ``ResultStream`` object, which takes the API call
99
arguments and returns a stream of results to the user.
1010
"""
1111

@@ -30,7 +30,7 @@
3030

3131
def make_session(username=None, password=None, bearer_token=None):
3232
"""Creates a Requests Session for use. Accepts a bearer token
33-
for freemium users and will override username and password information if
33+
for premiums users and will override username and password information if
3434
present.
3535
3636
Args:
@@ -113,7 +113,7 @@ def request(session, url, rule_payload, **kwargs):
113113
Args:
114114
session (requests.Session): the valid session object
115115
url (str): Valid API endpoint
116-
rule_payload (str or dict): rule package for the POST. if you pass a
116+
rule_payload (str or dict): rule package for the POST. If you pass a
117117
dictionary, it will be converted into JSON.
118118
"""
119119
if isinstance(rule_payload, dict):
@@ -187,8 +187,8 @@ def __init__(self, endpoint, rule_payload, username=None, password=None,
187187
def stream(self):
188188
"""
189189
Main entry point for the data from the API. Will automatically paginate
190-
through the results via the 'next' token and return up to `max_results`
191-
tweets or up to `max_requests` api calls, whichever is lower.
190+
through the results via the ``next`` token and return up to ``max_results``
191+
tweets or up to ``max_requests`` API calls, whichever is lower.
192192
193193
Usage:
194194
>>> result_stream = ResultStream(**kwargs)
@@ -235,12 +235,12 @@ def check_counts(self):
235235
Disables tweet parsing if the count API is used.
236236
"""
237237
if "counts" in re.split("[/.]", self.endpoint):
238-
logger.info("disabling tweet parsing due to counts api usage")
238+
logger.info("disabling tweet parsing due to counts API usage")
239239
self._tweet_func = lambda x: x
240240

241241
def execute_request(self):
242242
"""
243-
Sends the request to the api and parses the json response.
243+
Sends the request to the API and parses the json response.
244244
Makes some assumptions about the session length and sets the presence
245245
of a "next" token.
246246
"""
@@ -268,15 +268,15 @@ def __repr__(self):
268268

269269
def collect_results(rule, max_results=500, result_stream_args=None):
270270
"""
271-
Utility function to quickly get a list of tweets from a resultstream
272-
without keeping the object around. Rqequires your args to be configured
271+
Utility function to quickly get a list of tweets from a ``ResultStream``
272+
without keeping the object around. Requires your args to be configured
273273
prior to using.
274274
275275
Args:
276276
rule (str): valid powertrack rule for your account, preferably
277277
generated by the `gen_rule_payload` function.
278278
max_results (int): maximum number of tweets or counts to return from
279-
the API / underlying resultstream object.
279+
the API / underlying ``ResultStream`` object.
280280
result_stream_args (dict): configuration dict that has connection
281281
information for a ``ResultStream`` object.
282282

searchtweets/utils.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,17 @@ def write_ndjson(filename, data_iterable, append=False, **kwargs):
9898
def write_result_stream(result_stream, filename_prefix=None,
9999
results_per_file=None, **kwargs):
100100
"""
101-
Wraps a resultstream object to save it to a file. This function will still
101+
Wraps a ``ResultStream`` object to save it to a file. This function will still
102102
return all data from the result stream as a generator that wraps the
103-
`write_ndjson` method.
103+
``write_ndjson`` method.
104104
105105
Args:
106106
result_stream (ResultStream): the unstarted ResultStream object
107107
filename_prefix (str or None): the base name for file writing
108108
results_per_file (int or None): the maximum number of tweets to write
109109
per file. Defaults to having no max, which means one file. Multiple
110110
files will be named by datetime, according to
111-
"<prefix>_YYY-mm-ddTHH_MM_SS.json".
111+
``<prefix>_YYY-mm-ddTHH_MM_SS.json``.
112112
113113
"""
114114
if isinstance(result_stream, types.GeneratorType):
@@ -141,9 +141,7 @@ def write_result_stream(result_stream, filename_prefix=None,
141141
def read_config(filename):
142142
"""Reads and flattens a configuration file into a single
143143
dictionary for ease of use. Works with both ``.config`` and
144-
``.yaml`` files. Files should look like this:
145-
146-
.. code: yaml
144+
``.yaml`` files. Files should look like this::
147145
148146
search_rules:
149147
from-date: 2017-06-01
@@ -159,9 +157,8 @@ def read_config(filename):
159157
filename_prefix: kanye
160158
results_per_file: 10000000
161159
162-
or
160+
or::
163161
164-
.. parsed-literal:
165162
166163
[search_rules]
167164
from_date = 2017-06-01

tools/search_tweets.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,14 @@ def parse_cmd_args():
9696
argparser.add_argument("--max-results", dest="max_results",
9797
default=500,
9898
type=int,
99-
help="Maximum results to return for this "
100-
"session (defaults to 500; "
101-
"see -a option")
99+
help="Maximum number of Tweets or Counts to return for this "
100+
"session (defaults to 500)")
102101

103102
argparser.add_argument("--max-pages",
104103
dest="max_pages",
105104
type=int,
106105
default=None,
107-
help="Maximum number of pages/api calls to "
106+
help="Maximum number of pages/API calls to "
108107
"use for this session.")
109108

110109
argparser.add_argument("--results-per-file", dest="results_per_file",

0 commit comments

Comments
 (0)