Last active
July 17, 2020 09:20
-
-
Save BexTuychiev/1beb25d7a66ee42958d230368d231ff9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tops_posts_from_hashtag(hashtag_name: str, max_count: int): | |
""" | |
A function that downloads top {max_count} posts from a hashtag | |
""" | |
# Load the hashtag object into a variable | |
hashtag = instaloader.Hashtag.from_name(bot.context, hashtag_name) | |
# Get top posts in a generator | |
posts = hashtag.get_top_posts() | |
for index in range(1, max_count + 1): | |
try: | |
# Download the post | |
bot.download_post(next(posts), target=f'{hashtag_name}_{index}') | |
except: | |
break # If there are any errors, we break out of the loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment