Skip to content

Commit

Permalink
Fixes for instagram handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lepinkainen committed Feb 25, 2016
1 parent bab394c commit 4458608
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions pyfibot/modules/module_urltitle.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,15 +1150,15 @@ def _handle_dealextreme_www(url):


def _handle_instagram(url):
"""http*://instagram.com/p/*"""
"""http*://*instagram.com/p/*"""
from instagram.client import InstagramAPI

CLIENT_ID = '879b81dc0ff74f179f5148ca5752e8ce'

api = InstagramAPI(client_id=CLIENT_ID)

# todo: instagr.am
m = re.search('instagram\.com/p/([^/]+)', url)
m = re.search(r"instagram\.com/p/([^/]+)", url)
if not m:
return

Expand All @@ -1168,8 +1168,6 @@ def _handle_instagram(url):

media = api.media(r.json()['media_id'])

print(media)

# media type video/image?
# age/date? -> media.created_time # (datetime object)

Expand All @@ -1179,10 +1177,25 @@ def _handle_instagram(url):
else:
user = media.user.full_name

if media.like_count or media.comment_count:
info = "["
if media.like_count:
info += "%d ♥" % media.like_count
if media.comment_count:
info += ", %d comments" % media.comment_count
info += "]"
else:
info = ""

if media.caption:
return "%s: %s [%d likes, %d comments]" % (user, media.caption.text, media.like_count, media.comment_count)
if len(media.caption.text) > 145:
caption = "{0:.145}…".format(media.caption.text)
else:
caption = media.caption.text

return "%s: %s %s" % (user, caption, info)
else:
return "%s [%d likes, %d comments]" % (user, media.like_count, media.comment_count)
return "%s: %s" % (user, info)


def fetch_nettiX(url, fields_to_fetch):
Expand Down

0 comments on commit 4458608

Please sign in to comment.