Skip to content

Commit 3273804

Browse files
author
Yashh
committed
bare bones
0 parents  commit 3273804

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
A python wrapper for the upcoming pinterest API.
2+
3+
Stay tuned.

pinterest/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__version__ = 0.1
2+
3+
from client import PinterestAPI

pinterest/__init__.pyc

200 Bytes
Binary file not shown.

pinterest/client.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import urllib, urllib2
2+
3+
def ensure_access_token(f):
4+
def g(self, *args, **kwargs):
5+
if not self.access_token:
6+
raise PinterestException("You need an access token to make that call")
7+
f(self, *args, **kwargs)
8+
return g
9+
10+
class PinterestAPI(object):
11+
prefix_path = "https://api.pinterest.com/v2/"
12+
authorize_url = "https://api.pinterest.com/oauth/authorize"
13+
access_token_url = "https://api.pinterest.com/oauth/access_token"
14+
15+
def __init__(self, access_token=None):
16+
self.access_token = access_token
17+
18+
@ensure_access_token
19+
def _get_request(self, path, params={}):
20+
params["access_token"] = self.access_token
21+
url = "%s%s?%s" %(self.prefix_path, path, urllib.urlencode(params))
22+
try:
23+
return urllib2.urlopen(url).read()
24+
except urllib2.HTTPError, err:
25+
raise PinterestException(err.read())
26+
27+
def get_homefeed(self, page=1, limit=20):
28+
return self._get_request("home", {"page": page, "limit": limit})
29+
30+
def get_pin(self, pin_id):
31+
return self._get_request("pin/%d" %(pin_id))
32+
33+
34+
class PinterestException(Exception):
35+
def __init__(self, description):
36+
self.description = description
37+
38+
def __str__(self):
39+
return self.description
40+

pinterest/client.pyc

2.24 KB
Binary file not shown.

setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
from setuptools import setup, find_packages
3+
4+
setup(name="python-pinterest",
5+
version="0.1.0",
6+
description="Pinterest API client",
7+
license="MIT",
8+
install_requires=["simplejson"],
9+
author="Pinterest",
10+
author_email="[email protected]",
11+
url="http://github.com/pinterest/python-pinterest",
12+
packages = find_packages(),
13+
keywords= "pinterest",
14+
zip_safe = True)
15+
16+

0 commit comments

Comments
 (0)