diff --git a/README.markdown b/README.markdown
index 0188b13..59b245b 100644
--- a/README.markdown
+++ b/README.markdown
@@ -2,18 +2,32 @@ Pybooru - Library for Danbooru API.
========================================================================
Pybooru is a library for Python for access to API Danbooru / Moebooru based sites.
-Version: **2.0**
+Version: **2.1**
Licensed under: **MIT License**
+Dependencies.
+-------------
+- Python: >= 2.7
+- [Simplejson](https://pypi.python.org/pypi/simplejson/) (Optional).
+
Installation.
------------------------------------------------------------------------
-For installation Pybooru.
+Pypi - Python Package Index:
+[Pybooru on Pypi](https://pypi.python.org/pypi/Pybooru/).
+```bash
+sudo pip install Pybooru
+```
+or
+```bash
+sudo easy_install Pybooru
+```
+Manual installation:
```bash
- git clone git://github.com/luquedaniel/pybooru.git
- cd pybooru
- sudo python setup.py build
- sudo python setup.py install
+git clone git://github.com/luquedaniel/pybooru.git
+cd pybooru
+sudo python setup.py build
+sudo python setup.py install
```
Example use.
@@ -31,6 +45,7 @@ for artist in artists:
Login example.
------------------------------------------------------------------------
+Default sites:
```python
from pybooru import Pybooru
@@ -39,5 +54,14 @@ client = Pybooru('Konachan', username='your-username', password='your-password')
client.comments_create(post_id=id, comment_body='Comment content')
```
+Other sites:
+```python
+from pybooru import Pybooru
+
+client = Pybooru('konachan.com', username='your-username', password='your-password', hashString='So-I-Heard-You-Like-Mupkids-?--%s--')
+
+client.comments_create(post_id=id, comment_body='Comment content')
+```
+
Special Thanks to.
------------------------------------------------------------------------
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..c772dd0
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,9 @@
+Pybooru is a library for Python for access to API Danbooru / Moebooru based sites.
+
+Version: 2.1 (stable).
+
+Changelog: https://github.com/LuqueDaniel/pybooru/blob/master/changelog.md
+
+More information: https://github.com/LuqueDaniel/pybooru/blob/master/README.markdown
+
+Github repository: https://github.com/LuqueDaniel/pybooru
diff --git a/changelog.md b/changelog.md
new file mode 100644
index 0000000..3421c05
--- /dev/null
+++ b/changelog.md
@@ -0,0 +1,8 @@
+Pybooru - Changelog
+===================
+
+. **Pybooru 2.1** - (10/14/2013)
+ - Added login suppport for any Moebooru based site.
+ - Fixed a bug: 22792a0
+ - Added new information in setup.py.
+ - Small changes.
\ No newline at end of file
diff --git a/clean_pycs.sh b/clean_pycs.sh
new file mode 100755
index 0000000..2350b82
--- /dev/null
+++ b/clean_pycs.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+find -iname '*.pyc' -delete
+
+fi
diff --git a/pybooru/__init__.py b/pybooru/__init__.py
index fd15b1a..67ef91f 100644
--- a/pybooru/__init__.py
+++ b/pybooru/__init__.py
@@ -6,8 +6,9 @@
Under MIT license.
"""
-__author__ = 'Daniel Luque '
-__version__ = '2.0'
+__author__ = 'Daniel Luque'
+__email__ = 'danielluque14 at gmail dot com'
+__version__ = '2.1'
__url__ = 'http://github.com/LuqueDaniel/pybooru'
#pybooru imports
diff --git a/pybooru/exceptions.py b/pybooru/exceptions.py
index 70d694e..159e206 100644
--- a/pybooru/exceptions.py
+++ b/pybooru/exceptions.py
@@ -3,7 +3,7 @@
"""
#pybooru impost
-from .resources import http_status_codes
+from .resources import HTTP_STATUS_CODES
class PybooruError(Exception):
@@ -25,11 +25,11 @@ def __init__(self, msg, http_code=None, url=None):
self.http_code = http_code
self.url = url
- if (http_code is not None) and (http_code in http_status_codes) and (
+ if (http_code is not None) and (http_code in HTTP_STATUS_CODES) and (
url is not None):
self.msg = '%i: %s, %s -- %s -- URL: %s' % (http_code,
- http_status_codes[http_code][0],
- http_status_codes[http_code][1], self.msg, url)
+ HTTP_STATUS_CODES[http_code][0],
+ HTTP_STATUS_CODES[http_code][1], self.msg, url)
def __str__(self):
"""This function return self.msg"""
diff --git a/pybooru/pybooru.py b/pybooru/pybooru.py
index 8d51c78..261635e 100755
--- a/pybooru/pybooru.py
+++ b/pybooru/pybooru.py
@@ -27,35 +27,39 @@
#pyborru exceptions imports
from .exceptions import PybooruError
#pybooru resources imports
-from .resources import api_base_url
-from .resources import site_list
+from .resources import API_BASE_URL
+from .resources import SITE_LIST
class Pybooru(object):
"""Pybooru class.
init Parameters:
- siteName: The site name in site_list.
+ siteName: The site name in SITE_LIST.
siteURL: URL of based Danbooru site.
username: Your username in site
(Required only for functions that modify the content).
- password: Your user password
+ password: Your user password in plain text.
(Required only for functions that modify the content).
+ hashString: string that is hashed.
+ (See the API of the site for more information).
Attributes:
siteName: Return site name.
siteURL: Return URL of based danbooru site.
username: Return user name.
- password: Return password.
+ password: Return password in plain text.
+ hashString: Return hashString.
"""
def __init__(self, siteName=None, siteURL=None, username=None,
- password=None):
+ password=None, hashString=None):
self.siteName = siteName
self.siteURL = siteURL
self.username = username
self.password = password
+ self.hashString = hashString
if (siteURL is not None) or (siteName is not None):
if type(siteName) is str:
@@ -75,8 +79,8 @@ def _site_name(self, siteName):
in the resources module.
"""
- if siteName in site_list.keys():
- self.siteURL = site_list[siteName]['url']
+ if siteName in SITE_LIST.keys():
+ self.siteURL = SITE_LIST[siteName]['url']
else:
raise PybooruError(
'The site name is not valid, use siteURL parameter'
@@ -101,26 +105,33 @@ def _url_validator(self, url):
self.siteURL = url
def _json_load(self, api_name, params=None):
- """Function for reading and returning JSON response.
+ """Function for read and return JSON response.
Parameters:
api_name: The NAME of the API function.
params: The parameters of the API function.
"""
- url = self.siteURL + api_base_url[api_name]['url']
+ url = self.siteURL + API_BASE_URL[api_name]['url']
#Autentication
- if api_base_url[api_name]['required_login'] is True:
- if self.siteName in site_list.keys():
+ if API_BASE_URL[api_name]['required_login'] is True:
+ if (self.siteName in SITE_LIST.keys()) or (self.hashString is not None):
if (self.username is not None) and (self.password is not None):
#Set login parameter
params['login'] = self.username
#Create hashed string
- has_string = site_list[self.siteName]['hashed_string'] % (
- self.password)
-
+ if self.hashString is not None:
+ try:
+ has_string = self.hashString % (self.password)
+ except TypeError:
+ raise PybooruError('Use "%s" for hashString')
+ else:
+ has_string = SITE_LIST[self.siteName]['hashed_string'] % (
+ self.password)
+
+ #Set password_hash parameter
#Convert hashed_string to SHA1 and return hex string
params['password_hash'] = hashlib.sha1(
has_string).hexdigest()
@@ -129,13 +140,17 @@ def _json_load(self, api_name, params=None):
raise PybooruError('username and password is required')
else:
- raise PybooruError('Login in %s unsupported' % self.siteName)
+ raise PybooruError('Login in %s unsupported, please use hashString' % self.siteName)
#JSON request
try:
- #urlopen() from module urllib2
- #urlencode() from module urllib
- openURL = urlopen(url, urlencode(params))
+ if params is not None:
+ #urlopen() from module urllib2
+ #urlencode() from module urllib
+ openURL = urlopen(url, urlencode(params))
+ else:
+ openURL = urlopen(url)
+
reading = openURL.read()
#loads() is a function of simplejson module
response = loads(reading)
diff --git a/pybooru/resources.py b/pybooru/resources.py
index b77f440..afcfae6 100644
--- a/pybooru/resources.py
+++ b/pybooru/resources.py
@@ -7,7 +7,7 @@
"""
#site_list
-site_list = {
+SITE_LIST = {
'konachan': {
'url': 'http://konachan.com',
'hashed_string': 'So-I-Heard-You-Like-Mupkids-?--%s--'},
@@ -19,7 +19,7 @@
#api_base_url for the API functions
-api_base_url = {
+API_BASE_URL = {
'posts_list': {
'url': '/post.json',
'required_login': False},
@@ -144,7 +144,7 @@
#http_status_codes
-http_status_codes = {
+HTTP_STATUS_CODES = {
200: ('OK', 'Request was successful'),
403: ('Forbidden', 'Access denied'),
404: ('Not Found', 'Not found'),
diff --git a/setup.py b/setup.py
index 998cdaf..9339d63 100644
--- a/setup.py
+++ b/setup.py
@@ -1,19 +1,36 @@
#!/usr/bin/env python
+#setuptools imports
from setuptools import setup
from setuptools import find_packages
-__author__ = 'Daniel Luque '
-__version__ = '2.0'
+#pybooru imports
+import pybooru
+
+
+with open('README.rst', 'r') as f:
+ LONG_DESCRIPTION = f.read()
+
setup(
name='Pybooru',
- version=__version__,
- author=__author__,
+ version=pybooru.__version__,
+ author=pybooru.__author__,
+ description="Pybooru is a library for Python for access to API Danbooru / Moebooru based sites.",
+ long_description=LONG_DESCRIPTION,
author_email="danielluque14 at gmail dot com",
url="https://github.com/LuqueDaniel/pybooru",
license="MIT License",
+ keywords='Pybooru moebooru danbooru API',
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: MIT License',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ 'Topic :: Internet'
+ ],
+ platforms=['any'],
+ install_requires=['simplejson'],
packages=find_packages(),
include_package_data=True,
- install_requires=['simplejson'],
)