Skip to content

Commit 40cb158

Browse files
committed
ability to set --max-results for followers and friends
1 parent 27ed55a commit 40cb158

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

twarc/client2.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,6 @@ def following(
969969
expansions=None,
970970
tweet_fields=None,
971971
user_fields=None,
972-
media_fields=None,
973-
poll_fields=None,
974-
place_fields=None,
975972
pagination_token=None,
976973
):
977974
"""
@@ -989,9 +986,6 @@ def following(
989986
params = self._prepare_params(
990987
tweet_fields=tweet_fields,
991988
user_fields=user_fields,
992-
media_fields=media_fields,
993-
poll_fields=poll_fields,
994-
place_fields=place_fields,
995989
max_results=max_results,
996990
pagination_token=pagination_token,
997991
)
@@ -1008,9 +1002,6 @@ def followers(
10081002
expansions=None,
10091003
tweet_fields=None,
10101004
user_fields=None,
1011-
media_fields=None,
1012-
poll_fields=None,
1013-
place_fields=None,
10141005
pagination_token=None,
10151006
):
10161007
"""

twarc/command2.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,19 @@ def tweet(T, tweet_id, outfile, pretty):
696696
@click.option(
697697
"--limit",
698698
default=0,
699-
help="Maximum number of followers to save. Increments of 1000.",
699+
help="Maximum number of followers to save. Increments of 1000 or --max-results if set.",
700+
)
701+
@click.option(
702+
"--max-results",
703+
default=1000,
704+
help="Maximum number of users per page. Default is 1000.",
700705
)
701706
@command_line_progressbar_option
702707
@click.argument("user", type=str)
703708
@click.argument("outfile", type=click.File("w"), default="-")
704709
@click.pass_obj
705710
@cli_api_error
706-
def followers(T, user, outfile, limit, hide_progress):
711+
def followers(T, user, outfile, limit, max_results, hide_progress):
707712
"""
708713
Get the followers for a given user.
709714
"""
@@ -720,7 +725,7 @@ def followers(T, user, outfile, limit, hide_progress):
720725
lookup_total = target_user["public_metrics"]["followers_count"]
721726

722727
with tqdm(disable=hide_progress, total=lookup_total) as progress:
723-
for result in T.followers(user, user_id=user_id):
728+
for result in T.followers(user, user_id=user_id, max_results=max_results):
724729
_write(result, outfile)
725730
count += len(result["data"])
726731
progress.update(len(result["data"]))
@@ -731,14 +736,21 @@ def followers(T, user, outfile, limit, hide_progress):
731736

732737
@twarc2.command("following")
733738
@click.option(
734-
"--limit", default=0, help="Maximum number of friends to save. Increments of 1000."
739+
"--limit",
740+
default=0,
741+
help="Maximum number of friends to save. Increments of 1000 or --max-results if set.",
742+
)
743+
@click.option(
744+
"--max-results",
745+
default=1000,
746+
help="Maximum number of users per page. Default is 1000.",
735747
)
736748
@command_line_progressbar_option
737749
@click.argument("user", type=str)
738750
@click.argument("outfile", type=click.File("w"), default="-")
739751
@click.pass_obj
740752
@cli_api_error
741-
def following(T, user, outfile, limit, hide_progress):
753+
def following(T, user, outfile, limit, max_results, hide_progress):
742754
"""
743755
Get the users that a given user is following.
744756
"""
@@ -755,7 +767,7 @@ def following(T, user, outfile, limit, hide_progress):
755767
lookup_total = target_user["public_metrics"]["following_count"]
756768

757769
with tqdm(disable=hide_progress, total=lookup_total) as progress:
758-
for result in T.following(user, user_id=user_id):
770+
for result in T.following(user, user_id=user_id, max_results=max_results):
759771
_write(result, outfile)
760772
count += len(result["data"])
761773
progress.update(len(result["data"]))

0 commit comments

Comments
 (0)