Skip to content

Commit

Permalink
Merge pull request #599 from DocNow/add_singular_user_cli
Browse files Browse the repository at this point in the history
Add the singular user command, analogous to the single tweet command
  • Loading branch information
igorbrigadir authored Mar 12, 2022
2 parents c160d4a + 82c926e commit 6221fc6
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions twarc/command2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,40 @@ def users(T, infile, outfile, usernames, hide_progress, **kwargs):
progress.update_with_result(result, error_resource_type="user")


@twarc2.command("user")
@command_line_expansions_shortcuts
@command_line_expansions_options
@click.argument("name-or-id", type=click.Choice(["name", "id"]))
@click.argument("user", type=str)
@click.argument("outfile", type=click.File("w"), default="-")
@click.pass_obj
@cli_api_error
def user(T, name_or_id, user, outfile, **kwargs):
"""
Get the profile data for a single user by either username or ID.
To look up a user by ID:
twarc2 user id 12
To look up a user by username:
twarc2 user name jack
"""

kwargs = _process_expansions_shortcuts(kwargs)
# Also remove media poll and place from kwargs, these are not valid for this endpoint:
kwargs.pop("media_fields", None)
kwargs.pop("poll_fields", None)
kwargs.pop("place_fields", None)

username = name_or_id == "name"

user_data = list(T.user_lookup([user], username, **kwargs))
_write(user_data, outfile)


@twarc2.command("mentions")
@command_line_search_options
@command_line_expansions_shortcuts
Expand Down

0 comments on commit 6221fc6

Please sign in to comment.