Currently, the below code returns all the posts from the profile:
profilename = 'oneplus'
loader = instaloader.Instaloader()
profile = Profile.from_username(loader.context,profilename)
posts = profile.get_posts()
If the profile has, say 3000 posts, it takes a lot of time to load for instaloader.
However, I just want most recent n posts, and n<10, how do I do that?
finally came across something handy!
Firstly:
pip install func_timeout
Imagine your function was:
Then use it like so:
For me, it works like a charm.
Note: if you are thinking of downloading the posts, make sure you also timeout control the download function, as the function scans all the comments, which can get pretty lengthy.
If in trouble, visit the website where I found it: https://pypi.org/project/func-timeout/
Cheers