Skip to content

Instantly share code, notes, and snippets.

@blha303
Last active August 18, 2016 07:07
Show Gist options
  • Save blha303/f29597b08d646a130bc45b3f11f2d63e to your computer and use it in GitHub Desktop.
Save blha303/f29597b08d646a130bc45b3f11f2d63e to your computer and use it in GitHub Desktop.
from util import hook,http,web
from json import loads
from urllib2 import HTTPError
oldplugin = """@hook.regex(r'instagram.com/p/(.+?)/')
def ig_regex(match, bot=None):
"Returns info for instagram urls "
token = bot.config.get("api_keys", {}).get("instagram", None)
try:
data = http.get_json("https://api.instagram.com/v1/media/shortcode/{}?access_token={}".format(match.group(1), token))["data"]
return u"{caption[from][full_name]}: \"{caption[text]}\" ({likes[count]} likes)".format(**dict(emoji=u"\u1F5BC" if data["type"] == "image" else u"\u1F4FC", **data))
except (ValueError, HTTPError, KeyError) as e:
raise
"""
@hook.regex(r'instagram.com/p/(.+?)/')
def ig_regex(match):
"Now with more scraping because of stupid api use cases"
page = http.get("https://instagram.com/p/{}/".format(match.group(1)), user_agent=http.ua_chrome)
data = loads(page.split('<script type="text/javascript">window._sharedData = ')[1].split(";</script>")[0])["entry_data"]["PostPage"][0]["media"]
return u'{owner[full_name]} ({owner[username]}): "{caption}" ({likes[count]} likes)'.format(**data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment