{Post,Profile,StoryItem}.get_node() -> ._as_dict()
This is consistend with namedtuple._as_dict() and marks it as a protected member, which is good as it should be only accessed by save_structure_to_file().
This commit is contained in:
parent
3dcfcff04c
commit
4dcb23cfe5
@ -75,13 +75,13 @@ class Post:
|
|||||||
"""Create a post object from a given mediaid"""
|
"""Create a post object from a given mediaid"""
|
||||||
return cls.from_shortcode(context, mediaid_to_shortcode(mediaid))
|
return cls.from_shortcode(context, mediaid_to_shortcode(mediaid))
|
||||||
|
|
||||||
def get_node(self):
|
def _asdict(self):
|
||||||
if self._full_metadata_dict:
|
if self._full_metadata_dict:
|
||||||
node = self._full_metadata_dict
|
node = self._full_metadata_dict
|
||||||
else:
|
else:
|
||||||
node = self._node
|
node = self._node
|
||||||
if self._owner_profile:
|
if self._owner_profile:
|
||||||
node['owner'] = self.owner_profile.get_node()
|
node['owner'] = self.owner_profile._asdict()
|
||||||
if self._location:
|
if self._location:
|
||||||
node['location'] = self._location._asdict()
|
node['location'] = self._location._asdict()
|
||||||
return node
|
return node
|
||||||
@ -399,7 +399,7 @@ class Profile:
|
|||||||
username = Post.from_mediaid(context, int(data['edges'][0]["node"]["id"])).owner_username
|
username = Post.from_mediaid(context, int(data['edges'][0]["node"]["id"])).owner_username
|
||||||
return cls(context, {'username': username.lower(), 'id': profile_id})
|
return cls(context, {'username': username.lower(), 'id': profile_id})
|
||||||
|
|
||||||
def get_node(self):
|
def _asdict(self):
|
||||||
json_node = self._node.copy()
|
json_node = self._node.copy()
|
||||||
# remove posts
|
# remove posts
|
||||||
json_node.pop('edge_media_collections', None)
|
json_node.pop('edge_media_collections', None)
|
||||||
@ -578,10 +578,10 @@ class StoryItem:
|
|||||||
self._node = node
|
self._node = node
|
||||||
self._owner_profile = owner_profile
|
self._owner_profile = owner_profile
|
||||||
|
|
||||||
def get_node(self):
|
def _asdict(self):
|
||||||
node = self._node
|
node = self._node
|
||||||
if self._owner_profile:
|
if self._owner_profile:
|
||||||
node['owner'] = self._owner_profile.get_node()
|
node['owner'] = self._owner_profile._asdict()
|
||||||
return node
|
return node
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -776,7 +776,7 @@ def save_structure_to_file(structure: JsonExportable, filename: str) -> None:
|
|||||||
:param structure: :class:`Post`, :class:`Profile` or :class:`StoryItem`
|
:param structure: :class:`Post`, :class:`Profile` or :class:`StoryItem`
|
||||||
:param filename: Filename, ends in '.json' or '.json.xz'
|
:param filename: Filename, ends in '.json' or '.json.xz'
|
||||||
"""
|
"""
|
||||||
json_structure = {'node': structure.get_node(),
|
json_structure = {'node': structure._asdict(),
|
||||||
'instaloader': {'version': __version__, 'node_type': structure.__class__.__name__}}
|
'instaloader': {'version': __version__, 'node_type': structure.__class__.__name__}}
|
||||||
compress = filename.endswith('.xz')
|
compress = filename.endswith('.xz')
|
||||||
if compress:
|
if compress:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user