1
0
mirror of https://github.com/instaloader/instaloader.git synced 2024-11-09 03:42:31 +01: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'], lambda d: d['data']['shortcode_media']['edge_liked_by'],
self._rhx_gis)) 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 @property
def location(self) -> Optional[PostLocation]: def location(self) -> Optional[PostLocation]:
""" """