Skip to content

Commit

Permalink
instagram: change canonical base url http://instagram.com/ => https:/…
Browse files Browse the repository at this point in the history
…/www.instagram.com/

since they 301 redirect all http://instagram.com/... URLs to https://www.instagram.com/... anyway
  • Loading branch information
snarfed committed Feb 18, 2016
1 parent 15ca191 commit 74aed5c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions granary/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def urlopen(self, url, **kwargs):
return resp if kwargs.get('data') else json.loads(resp.read()).get('data')

def user_url(self, username):
return 'http://instagram.com/' + username
return 'https://www.instagram.com/%s/' % username

def get_actor(self, user_id=None):
"""Returns a user as a JSON ActivityStreams actor dict.
Expand Down Expand Up @@ -562,7 +562,7 @@ def html_to_activities(self, html):
# preprocess to make its field names match the API's
dims = media.get('dimensions', {})
media.update({
'link': 'http://instagram.com/p/%s/' % media.get('code'),
'link': 'https://www.instagram.com/p/%s/' % media.get('code'),
'user': media.get('owner', {}),
'created_time': media.get('date'),
'caption': {'text': media.get('caption')},
Expand Down
62 changes: 31 additions & 31 deletions granary/test/test_instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def tag_uri(name):
'id': '123_456',
'filter': 'Normal',
'created_time': '1348291542',
'link': 'http://instagram.com/p/ABC123/',
'link': 'https://www.instagram.com/p/ABC123/',
'user_has_liked': False,
'attribution': None,
'location': {
Expand Down Expand Up @@ -108,7 +108,7 @@ def tag_uri(name):
VIDEO = {
'type': 'video',
'id': '123_456',
'link': 'http://instagram.com/p/ABC123/',
'link': 'https://www.instagram.com/p/ABC123/',
'videos': {
'low_resolution': {
'url': 'http://distilleryvesper9-13.ak.instagram.com/090d06dad9cd11e2aa0912313817975d_102.mp4',
Expand Down Expand Up @@ -159,12 +159,12 @@ def tag_uri(name):
'username': 'averygood',
'displayName': '\u5c0f\u6b63',
'image': {'url': 'http://picture/commenter'},
'url': 'http://instagram.com/averygood',
'url': 'https://www.instagram.com/averygood/',
},
'content': '\u592a\u53ef\u7231\u4e86\u3002cute\uff0cvery cute',
'id': tag_uri('789'),
'published': '2012-10-07T05:45:57',
'url': 'http://instagram.com/p/ABC123/#comment-789',
'url': 'https://www.instagram.com/p/ABC123/#comment-789',
'inReplyTo': [{'id': tag_uri('123_456')}],
'to': [{'objectType':'group', 'alias':'@public'}],
},
Expand All @@ -175,7 +175,7 @@ def tag_uri(name):
'content': 'this picture -> is #abc #xyz',
'id': tag_uri('123_456'),
'published': '2012-09-22T05:25:42',
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'image': {'url': 'http://attach/image/big'},
'to': [{'objectType':'group', 'alias':'@public'}],
'location': {
Expand Down Expand Up @@ -234,7 +234,7 @@ def tag_uri(name):
'verb': 'post',
'published': '2012-09-22T05:25:42',
'id': tag_uri('123_456'),
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'actor': ACTOR,
'object': POST_OBJ,
}
Expand All @@ -260,24 +260,24 @@ def tag_uri(name):
}
LIKE_OBJS = [{ # ActivityStreams
'id': tag_uri('123_456_liked_by_8'),
'url': 'http://instagram.com/p/ABC123/#liked-by-8',
'url': 'https://www.instagram.com/p/ABC123/#liked-by-8',
'objectType': 'activity',
'verb': 'like',
'object': { 'url': 'http://instagram.com/p/ABC123/'},
'object': { 'url': 'https://www.instagram.com/p/ABC123/'},
'author': {
'objectType': 'person',
'id': tag_uri('8'),
'displayName': 'Alice',
'username': 'alizz',
'url': 'http://instagram.com/alizz',
'url': 'https://www.instagram.com/alizz/',
'image': {'url': 'http://alice/picture'},
},
}, {
'id': tag_uri('123_456_liked_by_9'),
'url': 'http://instagram.com/p/ABC123/#liked-by-9',
'url': 'https://www.instagram.com/p/ABC123/#liked-by-9',
'objectType': 'activity',
'verb': 'like',
'object': { 'url': 'http://instagram.com/p/ABC123/'},
'object': { 'url': 'https://www.instagram.com/p/ABC123/'},
'author': {
'objectType': 'person',
'id': tag_uri('9'),
Expand Down Expand Up @@ -325,7 +325,7 @@ def tag_uri(name):
'url': 'http://distilleryimage2.ak.instagram.com/11f75f1cd9cc11e2a0fd22000aa8039a_7.jpg'
},
'author': ACTOR,
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'replies': {
'items': COMMENT_OBJS,
'totalItems': len(COMMENT_OBJS),
Expand All @@ -336,7 +336,7 @@ def tag_uri(name):
'objectType': 'video'
}
VIDEO_ACTIVITY = {
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'object': VIDEO_OBJ,
'actor': ACTOR,
'verb': 'post',
Expand Down Expand Up @@ -381,15 +381,15 @@ def tag_uri(name):
<activity:object-type>http://activitystrea.ms/schema/1.0/photo</activity:object-type>
<id>http://instagram.com/p/ABC123/</id>
<id>https://www.instagram.com/p/ABC123/</id>
<title>this picture -&gt; is #abc #xyz</title>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
this picture -&gt; is #abc #xyz
<p>
<a class="link" href="http://instagram.com/p/ABC123/">
<a class="link" href="https://www.instagram.com/p/ABC123/">
<img class="thumbnail" src="http://attach/image/big" alt="" />
</a>
</p>
Expand All @@ -401,8 +401,8 @@ def tag_uri(name):
</div>
</content>
<link rel="alternate" type="text/html" href="http://instagram.com/p/ABC123/" />
<link rel="ostatus:conversation" href="http://instagram.com/p/ABC123/" />
<link rel="alternate" type="text/html" href="https://www.instagram.com/p/ABC123/" />
<link rel="ostatus:conversation" href="https://www.instagram.com/p/ABC123/" />
<link rel="ostatus:attention" href="http://snarfed.org" />
<link rel="mentioned" href="http://snarfed.org" />
Expand All @@ -417,7 +417,7 @@ def tag_uri(name):
<georss:featureName>Le Truc</georss:featureName>
<link rel="self" type="application/atom+xml" href="http://instagram.com/p/ABC123/" />
<link rel="self" type="application/atom+xml" href="https://www.instagram.com/p/ABC123/" />
</entry>
</feed>
Expand Down Expand Up @@ -590,23 +590,23 @@ def tag_uri(name):
'id': tag_uri('54861273'),
'image': {'url': 'https://scontent-sjc2-1.cdninstagram.com/hphotos-frc/t51.2885-19/10903606_836522793073208_584898992_a.jpg'},
'objectType': 'person',
'url': 'http://instagram.com/jc',
'url': 'https://www.instagram.com/jc/',
'username': 'jc',
}
HTML_ACTIVITIES = [{ # ActivityStreams
# Photo
'verb': 'post',
'published': '2016-01-17T20:46:33',
'id': tag_uri('123_456'),
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'actor': HTML_ACTOR,
'object': {
'objectType': 'photo',
'author': HTML_ACTOR,
'content': 'Elvis hits out of RCA Studio B',
'id': tag_uri('123_456'),
'published': '2016-01-17T20:46:33',
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'image': {'url': 'https://scontent-sjc2-1.cdninstagram.com/hphotos-xfp1/t51.2885-15/e35/12545499_1662965520652470_1466520818_n.jpg'},
'to': [{'objectType':'group', 'alias':'@public'}],
'location': {
Expand All @@ -632,15 +632,15 @@ def tag_uri(name):
'verb': 'post',
'published': '2016-01-17T13:15:52',
'id': tag_uri('123_456'),
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'actor': HTML_ACTOR,
'object': {
'objectType': 'video',
'author': HTML_ACTOR,
'content': 'Eye of deer \ud83d\udc41 and #selfie from me',
'id': tag_uri('123_456'),
'published': '2016-01-17T13:15:52',
'url': 'http://instagram.com/p/ABC123/',
'url': 'https://www.instagram.com/p/ABC123/',
'image': {'url': 'https://scontent-sjc2-1.cdninstagram.com/hphotos-xpf1/t51.2885-15/s750x750/sh0.08/e35/12424348_567037233461060_1986731502_n.jpg'},
'to': [{'objectType':'group', 'alias':'@private'}],
'stream': {
Expand Down Expand Up @@ -821,7 +821,7 @@ def test_media_to_object_with_likes(self):
def test_comment_to_object(self):
for cmt, obj in zip(COMMENTS, COMMENT_OBJS):
self.assert_equals(obj, self.instagram.comment_to_object(
cmt, '123_456', 'http://instagram.com/p/ABC123/'))
cmt, '123_456', 'https://www.instagram.com/p/ABC123/'))

def test_user_to_actor(self):
self.assert_equals(ACTOR, self.instagram.user_to_actor(USER))
Expand All @@ -831,7 +831,7 @@ def test_user_to_actor_url_fallback(self):
del user['website']
del user['bio']
actor = copy.deepcopy(ACTOR)
actor['url'] = 'http://instagram.com/snarfed'
actor['url'] = 'https://www.instagram.com/snarfed/'
del actor['urls']
del actor['description']
self.assert_equals(actor, self.instagram.user_to_actor(user))
Expand All @@ -842,7 +842,7 @@ def test_user_to_actor_displayName_fallback(self):
'id': tag_uri('420973239'),
'username': 'snarfed',
'displayName': 'snarfed',
'url': 'http://instagram.com/snarfed',
'url': 'https://www.instagram.com/snarfed/',
}, self.instagram.user_to_actor({
'id': '420973239',
'username': 'snarfed',
Expand Down Expand Up @@ -969,17 +969,17 @@ def test_create_comments_disabled(self):
def test_base_object(self):
self.assertEquals({
'id': '123',
'url': 'http://instagram.com/p/zHA5BLo1Mo/',
'url': 'https://www.instagram.com/p/zHA5BLo1Mo/',
}, self.instagram.base_object({
'id': tag_uri('123_456_liked_by_789'),
'object': {'url': 'http://instagram.com/p/zHA5BLo1Mo/'},
'object': {'url': 'https://www.instagram.com/p/zHA5BLo1Mo/'},
}))

# with only URL, we don't know id
self.assertEquals(
{'url': 'http://instagram.com/p/zHA5BLo1Mo/'},
{'url': 'https://www.instagram.com/p/zHA5BLo1Mo/'},
self.instagram.base_object({
'object': {'url': 'http://instagram.com/p/zHA5BLo1Mo/'},
'object': {'url': 'https://www.instagram.com/p/zHA5BLo1Mo/'},
}))

def test_html_to_activities(self):
Expand All @@ -996,6 +996,6 @@ def test_html_to_activities_missing_profile_picture_external_url(self):
HTML_FEED_HEADER + json.dumps(data) + HTML_FEED_FOOTER)

expected = copy.deepcopy(HTML_VIEWER)
expected['url'] = 'http://instagram.com/snarfed'
expected['url'] = 'https://www.instagram.com/snarfed/'
del expected['image']
self.assert_equals(expected, viewer)

0 comments on commit 74aed5c

Please sign in to comment.