From 413365c5a97bee8703228eacff145595f695d8a4 Mon Sep 17 00:00:00 2001 From: Kleber Soares Date: Sun, 4 Sep 2016 03:30:06 -0300 Subject: [PATCH] Fix data bug and media feed --- instagram/client.py | 2 +- instagram/models.py | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/instagram/client.py b/instagram/client.py index 624bc0ec..3ddb2f5e 100644 --- a/instagram/client.py +++ b/instagram/client.py @@ -94,7 +94,7 @@ def __init__(self, *args, **kwargs): root_class=Media) user_media_feed = bind_method( - path="/users/self/feed", + path="/users/self/media/feed", accepts_parameters=MEDIA_ACCEPT_PARAMETERS, root_class=Media, paginates=True) diff --git a/instagram/models.py b/instagram/models.py index d2517ca2..7b9ae7a2 100644 --- a/instagram/models.py +++ b/instagram/models.py @@ -96,27 +96,33 @@ def object_from_dictionary(cls, entry): new_media.comment_count = entry['comments']['count'] new_media.comments = [] - for comment in entry['comments']['data']: - new_media.comments.append(Comment.object_from_dictionary(comment)) + if "data" in entry["comments"]: + for comment in entry['comments']['data']: + new_media.comments.append( + Comment.object_from_dictionary(comment)) new_media.users_in_photo = [] if entry.get('users_in_photo'): for user_in_photo in entry['users_in_photo']: - new_media.users_in_photo.append(UserInPhoto.object_from_dictionary(user_in_photo)) + new_media.users_in_photo.append( + UserInPhoto.object_from_dictionary(user_in_photo)) new_media.created_time = timestamp_to_datetime(entry['created_time']) if entry['location'] and 'id' in entry: - new_media.location = Location.object_from_dictionary(entry['location']) + new_media.location = Location.object_from_dictionary( + entry['location']) new_media.caption = None if entry['caption']: - new_media.caption = Comment.object_from_dictionary(entry['caption']) - + new_media.caption = Comment.object_from_dictionary( + entry['caption']) + new_media.tags = [] if entry['tags']: for tag in entry['tags']: - new_media.tags.append(Tag.object_from_dictionary({'name': tag})) + new_media.tags.append( + Tag.object_from_dictionary({'name': tag})) new_media.link = entry['link']