a work in progress
This commit is contained in:
commit
8b7ec8e5f3
31
LICENSE
Normal file
31
LICENSE
Normal file
@ -0,0 +1,31 @@
|
||||
BSD-style license
|
||||
=================
|
||||
|
||||
Copyright (c) 2008, Sunlight Labs
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
* Neither the name of Sunlight Labs nor the names of its contributors may be
|
||||
used to endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@ -0,0 +1 @@
|
||||
include LICENSE *.rst *.py
|
37
README.rst
Normal file
37
README.rst
Normal file
@ -0,0 +1,37 @@
|
||||
==================
|
||||
python-sunlightapi
|
||||
==================
|
||||
|
||||
Python library for interacting with the Disqus API.
|
||||
|
||||
Documentation for the Disqus API is available at http://wiki.disqus.net/API
|
||||
|
||||
Written by James Turk <james.p.turk@gmail.com>.
|
||||
|
||||
All code is under a BSD-style license, see LICENSE for details.
|
||||
|
||||
Homepage: http://pypi.python.org/pypi/python-disqus/
|
||||
|
||||
Source: http://github.com/jamesturk/python-disqus/
|
||||
|
||||
|
||||
Requirements
|
||||
============
|
||||
|
||||
python >= 2.4
|
||||
|
||||
simplejson >= 1.8 (not required with python 2.6, will use built in json module)
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
To install run
|
||||
|
||||
``python setup.py install``
|
||||
|
||||
which will install the bindings into python's site-packages directory.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
I promise, I'll write this soon, bug me if you need docs.
|
97
disqus.py
Normal file
97
disqus.py
Normal file
@ -0,0 +1,97 @@
|
||||
""" Python library for interacting with the Disqus API.
|
||||
|
||||
The Disqus API (http://wiki.disqus.net/API) allows for interaction with
|
||||
the Disqus comment system.
|
||||
"""
|
||||
|
||||
__author__ = "James Turk (james.p.turk@gmail.com)"
|
||||
__version__ = "0.0.1"
|
||||
__copyright__ = "Copyright (c) 2009 James Turk"
|
||||
__license__ = "BSD"
|
||||
|
||||
import urllib, urllib2
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
import simplejson as json
|
||||
|
||||
api_url = 'http://disqus.com/api/%s/'
|
||||
|
||||
def apicall(method, params, http_method='GET'):
|
||||
params = urllib.urlencode(params)
|
||||
if http_method == 'GET':
|
||||
url = '?'.join((api_url % method, params))
|
||||
response = urllib2.urlopen(url).read()
|
||||
else:
|
||||
response = urllib2.urlopen(api_url % method, params).read()
|
||||
msg = json.loads(response)['message']
|
||||
return msg
|
||||
|
||||
class Thread(object):
|
||||
def __init__(self, d, forum_api_key):
|
||||
for k,v in d.iteritems():
|
||||
setattr(self, k, v)
|
||||
self.forum_api_key = forum_api_key
|
||||
|
||||
def get_posts(self):
|
||||
return apicall('get_thread_posts', {'forum_api_key': self.forum_api_key,
|
||||
'thread_id': self.id})
|
||||
|
||||
def update(self, title=None, slug=None, url=None, allow_comments=None):
|
||||
params = {'forum_api_key': self.forum_api_key, 'thread_id': self.id}
|
||||
if title:
|
||||
params['title'] = title
|
||||
if slug:
|
||||
params['slug'] = slug
|
||||
if url:
|
||||
params['url'] = url
|
||||
if allow_comments is not None:
|
||||
params['allow_comments'] = allow_comments
|
||||
return apicall('update_thread', params, 'POST')
|
||||
|
||||
class Forum(object):
|
||||
def __init__(self, d):
|
||||
for k,v in d.iteritems():
|
||||
setattr(self, k, v)
|
||||
self._api_key = None
|
||||
|
||||
@property
|
||||
def api_key(self):
|
||||
if not self._api_key:
|
||||
msg = apicall('get_forum_api_key', {'user_api_key':user_key,
|
||||
'forum_id':self.id})
|
||||
self._api_key = msg
|
||||
return self._api_key
|
||||
|
||||
def create_post(thread_id, message, author_name, author_email, parent_post=None,
|
||||
created_at=None, author_url=None, ip_address=None):
|
||||
params = {'forum_api_key': self.api_key, 'thread_id':thread_id, 'message':message, 'author_name':author_name, 'author_email':author_email}
|
||||
if parent_post:
|
||||
params['parent_post'] = parent_post
|
||||
if created_at:
|
||||
params['created_at'] = created_at
|
||||
if author_url:
|
||||
params['author_url'] = author_url
|
||||
if ip_address:
|
||||
params['ip_address'] = ip_address
|
||||
return apicall('create_post', params, 'POST')
|
||||
|
||||
def get_thread_list(self):
|
||||
msg = apicall('get_thread_list', {'forum_api_key':self.api_key})
|
||||
return [Thread(t, self.api_key) for t in msg]
|
||||
|
||||
def get_num_posts(self, *thread_ids):
|
||||
params = {'forum_api_key': self.api_key, 'thread_ids': ','.join(thread_ids)}
|
||||
return apicall('get_num_posts', params)
|
||||
|
||||
def get_thread_by_url(self, url):
|
||||
msg = apicall('get_thread_by_url', {'forum_api_key': self.api_key, 'url': url})
|
||||
return Thread(msg, self.api_key)
|
||||
|
||||
def thread_by_identifier(self, title, identifier):
|
||||
msg = apicall('thread_by_identifier', {'forum_api_key': self.api_key, 'title': title, 'identifier': identifier}, 'POST')
|
||||
return Thread(msg['thread'], self.api_key), msg['created']
|
||||
|
||||
def get_forum_list(user_key):
|
||||
msg = apicall('get_forum_list', {'user_api_key':user_key})
|
||||
return [Forum(f) for f in msg]
|
26
setup.py
Normal file
26
setup.py
Normal file
@ -0,0 +1,26 @@
|
||||
from distutils.core import setup
|
||||
from disqus import __version__,__license__,__doc__
|
||||
|
||||
license_text = open('LICENSE').read()
|
||||
long_description = open('README.rst').read()
|
||||
|
||||
setup(name="python-disqus",
|
||||
version=__version__,
|
||||
py_modules=["disqus"],
|
||||
description="Libraries for interacting with the Disqus API",
|
||||
author="James Turk",
|
||||
author_email = "james.p.turk@gmail.com",
|
||||
license=license_text,
|
||||
url="http://github.com/jamesturk/python-disqus/",
|
||||
long_description=long_description,
|
||||
platforms=["any"],
|
||||
classifiers=["Development Status :: 3 - Alpha",
|
||||
"Intended Audience :: Developers",
|
||||
"License :: OSI Approved :: BSD License",
|
||||
"Natural Language :: English",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
],
|
||||
install_requires=["simplejson >= 1.8"]
|
||||
)
|
Loading…
Reference in New Issue
Block a user