Skip to content

Commit

Permalink
Improving insta post-infos & user-infos
Browse files Browse the repository at this point in the history
Fix #962
  • Loading branch information
Yomguithereal committed Apr 16, 2024
1 parent 45171ed commit 67c5372
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
8 changes: 6 additions & 2 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -4156,7 +4156,7 @@ Usage: minet instagram post-infos [-h] [-c COOKIE] [--rcfile RCFILE] [--silent]
[--refresh-per-second REFRESH_PER_SECOND]
[--simple-progress] [-i INPUT]
[--explode EXPLODE] [-s SELECT]
[--total TOTAL] [-o OUTPUT]
[--total TOTAL] [--resume] [-o OUTPUT]
post_or_post_column
# Instagram post-infos
Expand Down Expand Up @@ -4206,6 +4206,8 @@ Optional Arguments:
-o, --output OUTPUT Path to the output file. Will consider `-` as
stdout. If not given, results will also be
printed to stdout.
--resume "Whether to resume from an aborted collection.
Need -o to be set.
--rcfile RCFILE Custom path to a minet configuration file. More
info about this here:
https://github.com/medialab/minet/blob/master/do
Expand Down Expand Up @@ -4490,7 +4492,7 @@ Usage: minet instagram user-infos [-h] [-c COOKIE] [--rcfile RCFILE] [--silent]
[--refresh-per-second REFRESH_PER_SECOND]
[--simple-progress] [-i INPUT]
[--explode EXPLODE] [-s SELECT]
[--total TOTAL] [-o OUTPUT]
[--total TOTAL] [--resume] [-o OUTPUT]
user_or_user_column
# Instagram user-infos
Expand Down Expand Up @@ -4542,6 +4544,8 @@ Optional Arguments:
-o, --output OUTPUT Path to the output file. Will consider `-` as
stdout. If not given, results will also be
printed to stdout.
--resume "Whether to resume from an aborted collection.
Need -o to be set.
--rcfile RCFILE Custom path to a minet configuration file. More
info about this here:
https://github.com/medialab/minet/blob/master/do
Expand Down
4 changes: 4 additions & 0 deletions minet/cli/instagram/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#
# Logic of the `insta` action.
#
from casanova import RowCountResumer

from minet.cli.argparse import command, ConfigAction

INSTAGRAM_COMMENTS_SUBCOMMAND = command(
Expand Down Expand Up @@ -152,6 +154,7 @@
"item_label_plural": "post urls, post shortcodes or post ids",
},
select=True,
resumer=RowCountResumer,
)

INSTAGRAM_USER_FOLLOWING_SUBCOMMAND = command(
Expand Down Expand Up @@ -231,6 +234,7 @@
"item_label": "username, user url or user id",
"item_label_plural": "usernames, user urls or user ids",
},
resumer=RowCountResumer
)

INSTAGRAM_USER_POSTS_SUBCOMMAND = command(
Expand Down
14 changes: 5 additions & 9 deletions minet/cli/instagram/post_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#
from minet.cli.utils import with_enricher_and_loading_bar
from minet.cli.instagram.utils import with_instagram_fatal_errors
from minet.cli.loading_bar import LoadingBar
from minet.instagram import InstagramAPIScraper
from minet.instagram.types import InstagramPost
from minet.instagram.exceptions import InstagramInvalidTargetError
Expand All @@ -15,20 +16,15 @@
@with_enricher_and_loading_bar(
headers=InstagramPost, title="Scraping infos", unit="posts"
)
def action(cli_args, enricher, loading_bar):
def action(cli_args, enricher, loading_bar: LoadingBar):
client = InstagramAPIScraper(cookie=cli_args.cookie)

for i, row, user in enricher.enumerate_cells(
cli_args.column, with_rows=True, start=1
):
for row, user in enricher.cells(cli_args.column, with_rows=True):
with loading_bar.step():
try:
result = client.post_infos(user)

enricher.writerow(row, result)

except InstagramInvalidTargetError:
loading_bar.print(
"Given post (line %i) is probably not an Instagram post: %s"
% (i, user)
)
loading_bar.inc_stat("not-found", style="warning")
enricher.writerow(row)
13 changes: 5 additions & 8 deletions minet/cli/instagram/user_infos.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Logic of the `instagram user-infos` action.
#
from minet.cli.utils import with_enricher_and_loading_bar
from minet.cli.loading_bar import LoadingBar
from minet.cli.instagram.utils import with_instagram_fatal_errors
from minet.instagram import InstagramAPIScraper
from minet.instagram.types import InstagramUserInfo
Expand All @@ -15,19 +16,15 @@
@with_enricher_and_loading_bar(
headers=InstagramUserInfo, title="Scraping infos", unit="users"
)
def action(cli_args, enricher, loading_bar):
def action(cli_args, enricher, loading_bar: LoadingBar):
client = InstagramAPIScraper(cookie=cli_args.cookie)

for i, row, user in enricher.enumerate_cells(
cli_args.column, with_rows=True, start=1
):
for row, user in enricher.cells(cli_args.column, with_rows=True):
with loading_bar.step():
try:
info = client.user_infos(user)
enricher.writerow(row, info)

except InstagramInvalidTargetError:
loading_bar.print(
"Given user (line %i) is probably not an Instagram user: %s"
% (i, user)
)
loading_bar.inc_stat("not-found", style="warning")
enricher.writerow(row)

0 comments on commit 67c5372

Please sign in to comment.