Skip to content

Instantly share code, notes, and snippets.

@franckverrot
Created February 20, 2010 08:25
Show Gist options
  • Save franckverrot/309585 to your computer and use it in GitHub Desktop.
Save franckverrot/309585 to your computer and use it in GitHub Desktop.
import simplejson
import urllib2
GEMCUTTER_API_URL = "http://gemcutter.org/api/v1/"
API_KEY_URL = GEMCUTTER_API_URL + "api_key"
GEMS_URL = GEMCUTTER_API_URL + 'gems/'
GEM_SEARCH_URL = GEMCUTTER_API_URL + 'search.json?query='
class Gem(object):
def __init__(self, jsoned_gem, format='json'):
if format == 'raw':
self.values = jsoned_gem
else:
self.values = simplejson.loads(jsoned_gem)
def __str__(self):
return str(self.values)
#todo dependencies
class Gemcutter(object):
def gem(self, gem_name):
try:
f = urllib2.urlopen(GEMS_URL+gem_name+'.json')
gem_info = f.read(40000)
return Gem(gem_info)
except:
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment