Skip to content

Commit 6b5eaa2

Browse files
committed
add fields nad expansions to 'tweet' command too
1 parent 9f32350 commit 6b5eaa2

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

twarc/command2.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,10 @@ def _process_expansions_shortcuts(kwargs):
580580
] = "author_id,in_reply_to_user_id,referenced_tweets.id,referenced_tweets.id.author_id,attachments.poll_ids,attachments.media_keys,geo.place_id"
581581
kwargs[
582582
"tweet_fields"
583-
] = "author_id,conversation_id,id,in_reply_to_user_id,referenced_tweets"
584-
kwargs["user_fields"] = "id,pinned_tweet_id,username"
583+
] = "id,conversation_id,author_id,in_reply_to_user_id,referenced_tweets"
584+
kwargs[
585+
"user_fields"
586+
] = "id,username,name,pinned_tweet_id" # pinned_tweet_id is the only extra one, id,username,name are always returned.
585587
kwargs["media_fields"] = "media_key"
586588
kwargs["poll_fields"] = "id"
587589
kwargs["place_fields"] = "id"
@@ -764,20 +766,25 @@ def counts(
764766

765767

766768
@twarc2.command("tweet")
769+
@command_line_expansions_shortcuts
770+
@command_line_expansions_options
767771
@click.option("--pretty", is_flag=True, default=False, help="Pretty print the JSON")
768772
@click.argument("tweet_id", type=str)
769773
@click.argument("outfile", type=click.File("w"), default="-")
770774
@click.pass_obj
771775
@cli_api_error
772-
def tweet(T, tweet_id, outfile, pretty):
776+
def tweet(T, tweet_id, outfile, pretty, **kwargs):
773777
"""
774778
Look up a tweet using its tweet id or URL.
775779
"""
780+
781+
kwargs = _process_expansions_shortcuts(kwargs)
782+
776783
if "https" in tweet_id:
777784
tweet_id = tweet_id.split("/")[-1]
778785
if not re.match("^\d+$", tweet_id):
779786
click.echo(click.style("Please enter a tweet URL or ID", fg="red"), err=True)
780-
result = next(T.tweet_lookup([tweet_id]))
787+
result = next(T.tweet_lookup([tweet_id], **kwargs))
781788
_write(result, outfile, pretty=pretty)
782789

783790

0 commit comments

Comments
 (0)