BigW Consortium Gitlab

Commit cb7f1f6e by Dan McKinley

readme

parents
*~
*egg-info*
build/
dist/
\ No newline at end of file
This diff is collapsed. Click to expand it.
# etsy-python
Python access to the Etsy API
By Dan McKinley - dan@etsy.com - [http://mcfunley.com](http://mcfunley.com)
## Installation
After downloading and extracting the tarball,
<pre>
$ python setup.py build
$ sudo python setup.py install
</pre>
## Example
To use, first [register for an Etsy developer key](http://developer.etsy.com/).
Below is an example session.
<pre>
$ python
python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from etsy import Etsy
>>> api = Etsy('YOUR-API-KEY-HERE')
>>> api.getFrontFeaturedListings(offset=10, limit=1)[0]['title']
'Artists Eco Journal - Landscape Watercolor - Rustic Vegan Hemp and Recycled Rubber'
</pre>
## Version History
### Version 0.1
* 05-24-2010 - Initial release
\ No newline at end of file
from __future__ import with_statement
from contextlib import closing
from simplejson.decoder import JSONDecoder
import urllib2
from urllib import urlencode
class Etsy(object):
api_url = 'http://beta-api.etsy.com/v1'
def __init__(self, api_key):
self.api_key = api_key
d = JSONDecoder()
self.decode = d.decode
for method in self.get('/'):
self.create_method(**method)
def create_method(self, name, description, uri, **kw):
def method(**kwargs):
return self.get(uri, **kwargs)
method.__name__ = name
method.__doc__ = description
setattr(self, name, method)
def get(self, url, **kwargs):
for k, v in kwargs.items():
arg = '{%s}' % k
if arg in url:
url = url.replace(arg, v)
kwargs.update(dict(api_key=self.api_key))
qs = urlencode(kwargs)
url = '%s%s?%s' % (self.api_url, url, qs)
with closing(urllib2.urlopen(url)) as f:
data = f.read()
self.data = self.decode(data)
self.count = self.data['count']
return self.data['results']
#!/usr/bin/python
import os
from setuptools import setup
this_dir = os.path.realpath(os.path.dirname(__file__))
long_description = open(os.path.join(this_dir, 'README.md'), 'r').read()
setup(
name = 'etsy-python',
version = '0.1',
author = 'Dan McKinley',
author_email = 'dan@etsy.com',
description = 'Python access to the Etsy API',
license = 'GPL v3',
keywords = 'etsy api handmade',
packages = ['etsy'],
long_description = long_description,
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment