Created
March 11, 2010 21:03
-
-
Save embedly/329646 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib | |
import urllib2 | |
try: | |
import json | |
except ImportError: | |
try: | |
import simplejson as json | |
except ImportError: | |
raise ImportError("Need a json decoder") | |
ACCEPTED_ARGS = ['maxwidth', 'maxheight', 'format'] | |
def get_oembed(url, **kwargs): | |
""" | |
Example Embedly oEmbed Function | |
""" | |
api_url = 'http://api.embed.ly/v1/api/oembed?' | |
params = {'url':url } | |
for key, value in kwargs.items(): | |
if key not in ACCEPTED_ARGS: | |
raise ValueError("Invalid Argument %s" % key) | |
params[key] = value | |
oembed_call = "%s%s" % (api_url, urllib.urlencode(params)) | |
return json.loads(urllib2.urlopen(oembed_call).read()) | |
if __name__ == "__main__": | |
urls = ["http://vimeo.com/9503416", | |
"http://twitpic.com/13whni"] | |
for url in urls: | |
print "\n\nurl: %s\n" % url | |
print get_oembed(url) | |
print "\n\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment