1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-09-11 16:22:24 +02:00

Post properties is_sponsored and sponsor_users

This allows to access the Paid Partnership With metadata of a Post.

Closes #295.
This commit is contained in:
Alexander Graf 2020-03-25 17:13:46 +01:00
parent 9c2e7c70ac
commit e725ca2640

View File

@ -413,6 +413,30 @@ class Post:
lambda d: d['data']['shortcode_media']['edge_liked_by'],
self._rhx_gis))
@property
def is_sponsored(self) -> bool:
"""
Whether Post is a sponsored post, equivalent to non-empty :meth:`Post.sponsor_users`.
.. versionadded:: 4.4
"""
try:
sponsor_edges = self._field('edge_media_to_sponsor_user', 'edges')
except KeyError:
return False
return bool(sponsor_edges)
@property
def sponsor_users(self) -> List['Profile']:
"""
The Post's sponsors.
.. versionadded:: 4.4
"""
return ([] if not self.is_sponsored else
[Profile(self._context, edge['node']['sponsor']) for edge in
self._field('edge_media_to_sponsor_user', 'edges')])
@property
def location(self) -> Optional[PostLocation]:
"""