Skip to content

Commit

Permalink
Merge pull request #121 from igorbrigadir/output-formats
Browse files Browse the repository at this point in the history
Docs and naming consistency for output format command line
  • Loading branch information
jimmoffitt authored Apr 14, 2021
2 parents 9396f05 + 4cbcb5c commit 039b9ee
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
4 changes: 1 addition & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ Command-line options
stored.
--no-print-stream disable print streaming
--print-stream Print tweet stream to stdout
--output-options Set output format:
--output-format Set output format:
'r' Unmodified API Responses. (default).
'a' Atomic Tweets: Tweet objects with expansions inline.
'm' Message Stream: Tweets, Expansions, and Metadata
as a stream of messages.
--atomic Output "Atomic" Tweet format.
Equivalent to setting --output-format 'a'.
--extra-headers EXTRA_HEADERS
JSON-formatted str representing a dict of additional
HTTP request headers
Expand Down
12 changes: 10 additions & 2 deletions scripts/poll_tweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def parse_cmd_args():

argparser.add_argument("--credential-file-key",
dest="credential_yaml_key",
default=None,
default="search_tweets_v2",
help=("the key in the credential file used "
"for this session's credentials. "
"Defaults to search_tweets_api"))
"Defaults to search_tweets_v2"))

argparser.add_argument("--env-overwrite",
dest="env_overwrite",
Expand Down Expand Up @@ -123,6 +123,14 @@ def parse_cmd_args():
default=None,
help="""A comma-delimited list of Twitter Poll JSON attributes to include in endpoint responses. (API default:"id")""")

argparser.add_argument("--output-format",
dest="output_format",
default="r",
help="""Set output format:
'r' Unmodified API [R]esponses. (default).
'a' [A]tomic Tweets: Tweet objects with expansions inline.
'm' [M]essage stream: Tweets, expansions, and pagination metadata as a stream of messages.""")

#client options.
argparser.add_argument("--max-tweets", dest="max_tweets",
type=int,
Expand Down
14 changes: 6 additions & 8 deletions scripts/search_tweets.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def parse_cmd_args():
"'max_results' in the API")

argparser.add_argument("--expansions",
dest="expansions",
default=None,
help="""A comma-delimited list of expansions. Specified expansions results in full objects in the 'includes' response object.""")
dest="expansions",
default=None,
help="""A comma-delimited list of expansions. Specified expansions results in full objects in the 'includes' response object.""")

argparser.add_argument("--tweet-fields",
dest="tweet_fields",
Expand All @@ -120,9 +120,9 @@ def parse_cmd_args():
default=None,
help="""A comma-delimited list of Twitter Poll JSON attributes to include in endpoint responses. (API default:"id")""")

argparser.add_argument("--output-option",
dest="output_option",
default=None,
argparser.add_argument("--output-format",
dest="output_format",
default="r",
help="""Set output format:
'r' Unmodified API [R]esponses. (default).
'a' [A]tomic Tweets: Tweet objects with expansions inline.
Expand Down Expand Up @@ -161,8 +161,6 @@ def parse_cmd_args():
default=True,
help="Print tweet stream to stdout")



argparser.add_argument("--extra-headers",
dest="extra_headers",
type=str,
Expand Down
2 changes: 1 addition & 1 deletion searchtweets/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def intify(arg):
"results_per_file": intify(config_dict.get("results_per_file")),
"max_tweets": intify(config_dict.get("max_tweets")),
"max_pages": intify(config_dict.get("max_pages", None)),
"output_option": config_dict.get("output_option")}
"output_format": config_dict.get("output_format")}

return _dict

Expand Down
6 changes: 2 additions & 4 deletions searchtweets/result_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class ResultStream:
session_request_counter = 0

def __init__(self, endpoint, request_parameters, bearer_token=None, extra_headers_dict=None, max_tweets=500,
max_requests=None, atomic=False, output_options="r", **kwargs):
max_requests=None, output_format="r", **kwargs):

self.bearer_token = bearer_token
self.extra_headers_dict = extra_headers_dict
Expand All @@ -193,9 +193,7 @@ def __init__(self, endpoint, request_parameters, bearer_token=None, extra_header
self.max_requests = (max_requests if max_requests is not None
else 10 ** 9)
self.endpoint = endpoint
if atomic:
self.output_format = "a"
self.output_format = output_options
self.output_format = output_format

def formatted_output(self):

Expand Down

0 comments on commit 039b9ee

Please sign in to comment.