Include top posts in download_hashtag()
This commit is contained in:
parent
b98e9941ae
commit
0e13c73b62
@ -926,7 +926,7 @@ class Instaloader:
|
|||||||
self.download_hashtag_profilepic(hashtag)
|
self.download_hashtag_profilepic(hashtag)
|
||||||
if posts:
|
if posts:
|
||||||
self.context.log("Retrieving pictures with hashtag #{}...".format(hashtag.name))
|
self.context.log("Retrieving pictures with hashtag #{}...".format(hashtag.name))
|
||||||
self.posts_download_loop(hashtag.get_posts(), target, fast_update, post_filter,
|
self.posts_download_loop(hashtag.get_all_posts(), target, fast_update, post_filter,
|
||||||
max_count=max_count)
|
max_count=max_count)
|
||||||
if self.save_metadata:
|
if self.save_metadata:
|
||||||
json_filename = '{0}/{1}'.format(self.dirname_pattern.format(profile=target,
|
json_filename = '{0}/{1}'.format(self.dirname_pattern.format(profile=target,
|
||||||
|
@ -1267,6 +1267,31 @@ class Hashtag:
|
|||||||
conn = data["edge_hashtag_to_media"]
|
conn = data["edge_hashtag_to_media"]
|
||||||
yield from (Post(self._context, edge["node"]) for edge in conn["edges"])
|
yield from (Post(self._context, edge["node"]) for edge in conn["edges"])
|
||||||
|
|
||||||
|
def get_all_posts(self) -> Iterator[Post]:
|
||||||
|
"""Yields all posts, i.e. all most recent posts and the top posts, in chronological order."""
|
||||||
|
sorted_top_posts = iter(sorted(self.get_top_posts(), key=lambda p: p.date_utc, reverse=True))
|
||||||
|
other_posts = self.get_posts()
|
||||||
|
next_top = next(sorted_top_posts, None)
|
||||||
|
next_other = next(other_posts, None)
|
||||||
|
while next_top is not None or next_other is not None:
|
||||||
|
if next_other is None:
|
||||||
|
yield from sorted_top_posts
|
||||||
|
break
|
||||||
|
if next_top is None:
|
||||||
|
yield from other_posts
|
||||||
|
break
|
||||||
|
if next_top == next_other:
|
||||||
|
yield next_top
|
||||||
|
next_top = next(sorted_top_posts, None)
|
||||||
|
next_other = next(other_posts, None)
|
||||||
|
continue
|
||||||
|
if next_top.date_utc > next_other.date_utc:
|
||||||
|
yield next_top
|
||||||
|
next_top = next(sorted_top_posts, None)
|
||||||
|
else:
|
||||||
|
yield next_other
|
||||||
|
next_other = next(other_posts, None)
|
||||||
|
|
||||||
|
|
||||||
class TopSearchResults:
|
class TopSearchResults:
|
||||||
"""
|
"""
|
||||||
|
@ -73,7 +73,7 @@ class TestInstaloaderAnonymously(unittest.TestCase):
|
|||||||
self.L.download_hashtag(HASHTAG, NORMAL_MAX_COUNT)
|
self.L.download_hashtag(HASHTAG, NORMAL_MAX_COUNT)
|
||||||
|
|
||||||
def test_hashtag_paging(self):
|
def test_hashtag_paging(self):
|
||||||
for count, post in enumerate(instaloader.Hashtag.from_name(L.context, HASHTAG).get_posts()):
|
for count, post in enumerate(instaloader.Hashtag.from_name(self.L.context, HASHTAG).get_all_posts()):
|
||||||
print(post)
|
print(post)
|
||||||
if count == PAGING_MAX_COUNT:
|
if count == PAGING_MAX_COUNT:
|
||||||
break
|
break
|
||||||
|
Loading…
x
Reference in New Issue
Block a user