Skip to content

Commit d3d694c

Browse files
author
Aaron Gonzales
committed
removed default arguments for results-per-call, max-results, and results-per-file to prevent overriding otherp potential argument sources; added better handling for sensitive arguments
1 parent a13552d commit d3d694c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

tools/search_tweets.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,13 @@ def parse_cmd_args():
8989

9090
argparser.add_argument("--results-per-call",
9191
dest="results_per_call",
92-
default=100,
9392
help="Number of results to return per call "
9493
"(default 100; max 500) - corresponds to "
9594
"'maxResults' in the API")
9695

9796
argparser.add_argument("--max-results", dest="max_results",
98-
default=500,
9997
type=int,
100-
help="Maximum number of Tweets or Counts to return for this "
101-
"session (defaults to 500)")
98+
help="Maximum number of Tweets or Counts to return for this session")
10299

103100
argparser.add_argument("--max-pages",
104101
dest="max_pages",
@@ -108,7 +105,7 @@ def parse_cmd_args():
108105
"use for this session.")
109106

110107
argparser.add_argument("--results-per-file", dest="results_per_file",
111-
default=0,
108+
default=None,
112109
type=int,
113110
help="Maximum tweets to save per file.")
114111

@@ -137,6 +134,10 @@ def parse_cmd_args():
137134
return argparser
138135

139136

137+
def _filter_sensitive_args(dict_):
138+
sens_args = ("password", "consumer_key", "consumer_secret", "bearer_token")
139+
return {k: v for k, v in dict_.items() if k not in sens_args}
140+
140141
def main():
141142
args_dict = vars(parse_cmd_args().parse_args())
142143
if args_dict.get("debug") is True:
@@ -149,8 +150,8 @@ def main():
149150
else:
150151
configfile_dict = {}
151152

152-
logger.debug("config file dict:")
153-
logger.debug(json.dumps(configfile_dict, indent=4))
153+
logger.debug("config file ({}) arguments sans sensitive args:".format(args_dict["config_filename"]))
154+
logger.debug(json.dumps(_filter_sensitive_args(configfile_dict), indent=4))
154155

155156
creds_dict = load_credentials(filename=args_dict["credential_file"],
156157
account_type=args_dict["account_type"],
@@ -163,24 +164,26 @@ def main():
163164
dict_filter(args_dict),
164165
dict_filter(creds_dict))
165166

166-
logger.debug("combined dict (cli, config, creds):")
167-
logger.debug(json.dumps(config_dict, indent=4))
167+
logger.debug("combined dict (cli, config, creds) sans password:")
168+
logger.debug(json.dumps(_filter_sensitive_args(config_dict), indent=4))
168169

169170
if len(dict_filter(config_dict).keys() & REQUIRED_KEYS) < len(REQUIRED_KEYS):
170171
print(REQUIRED_KEYS - dict_filter(config_dict).keys())
171172
logger.error("ERROR: not enough arguments for the program to work")
172173
sys.exit(1)
173174

174175
stream_params = gen_params_from_config(config_dict)
176+
logger.debug("full arguments passed to the ResultStream object sans password")
177+
logger.debug(json.dumps(_filter_sensitive_args(stream_params), indent=4))
175178

176179
rs = ResultStream(tweetify=False, **stream_params)
177180

178181
logger.debug(str(rs))
179182

180183
if config_dict.get("filename_prefix") is not None:
181184
stream = write_result_stream(rs,
182-
filename_prefix=config_dict["filename_prefix"],
183-
results_per_file=config_dict["results_per_file"])
185+
filename_prefix=config_dict.get("filename_prefix"),
186+
results_per_file=config_dict.get("results_per_file"))
184187
else:
185188
stream = rs.stream()
186189

0 commit comments

Comments
 (0)