Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Top X Photos of User #194

Closed
eyazilikaya opened this issue Oct 25, 2018 · 4 comments

Comments

@eyazilikaya
Copy link

commented Oct 25, 2018

Provide us a use case of the feature
If we can set a parameter for top photos and download X of them that would be a great feature. This parameter can be Engagement Rate, let's say a user has 10k followers and user has 500 media, if we sort all media by their engagement rate(likes+comments of media/follower count) and only download top 100 or top %10 of media, we can just eliminate downloading low engagement media.

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context about the feature request here.

@aandergr

This comment has been minimized.

Copy link
Member

commented Oct 29, 2018

This should better be implemented in a separate script rather than as an Instaloader feature. For the sake of documentation / examples, we can then publish it here: https://instaloader.github.io/codesnippets.html

@aandergr

This comment has been minimized.

Copy link
Member

commented Nov 1, 2018

This is an approach of a code snippet doing what you want:

from itertools import islice
from math import ceil

from instaloader import Instaloader, Profile

PROFILE = ...        # profile to download from
X_percentage = 10    # percentage of posts that should be downloaded

L = Instaloader()

profile = Profile.from_username(L.context, PROFILE)
posts_sorted_by_likes = sorted(profile.get_posts(), key = lambda p: p.likes + p.comments)

for post in islice(posts_sorted_by_likes, ceil(profile.mediacount * X_percentage / 100)):
    L.download_post(post, PROFILE)
@eyazilikaya

This comment has been minimized.

Copy link
Author

commented Nov 3, 2018

It worked perfectly. Thanks a lot @aandergr

@RualLozun

This comment has been minimized.

Copy link

commented Jul 25, 2019

This is an approach of a code snippet doing what you want:

from itertools import islice
from math import ceil

from instaloader import Instaloader, Profile

PROFILE = ...        # profile to download from
X_percentage = 10    # percentage of posts that should be downloaded

L = Instaloader()

profile = Profile.from_username(L.context, PROFILE)
posts_sorted_by_likes = sorted(profile.get_posts(), key = lambda p: p.likes + p.comments)

for post in islice(posts_sorted_by_likes, ceil(profile.mediacount * X_percentage / 100)):
    L.download_post(post, PROFILE)

It seems like this script downloads the least liked posts instead of the most liked posts... I made it work changing this line, thought it could be useful to somebody to know this:
posts_sorted_by_likes = sorted(profile.get_posts(), key = lambda p: p.likes + p.comments, reverse = True)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.