@@ -0,0 +1,6 @@
__all__ = [
'Query',
]

class Query(object):
pass
@@ -1,59 +1,25 @@
import e621apy.helpers as tools
"""
Contains the Search class
"""

__all__ = [
'SearchPost',
'Search',
]

class SearchPost(object):

RATING_SAFE = 'rating:safe'
RATING_QUESTIONABLE = 'rating:questionable'
RATING_EXPLICIT = 'rating:explicit'
RATING_ALL = 'rating:all'

def __init__(self, limit=75, tags=[], rating=RATING_SAFE):
self._limit = limit
self._matches = 0
self._tags = tags
self._add_tags(rating)

def _add_tags(self, *tags):
for tag in tags:
self._tags = tools._add_tag(self._tags, tag)

def _set_sort(self, key, asc):
sort = '_asc'
if not asc:
sort = '_desc'

self._add_tags('order:%s%s' % (key, sort))

def _set_id(self, id):
self._add_tags('id:%i' % id)

def rating(self, rating):
self._add_tags(rating)
return self

def tags(self, *tags):
self._add_tags(tags)
return self

def species(self, *species):
self._add_tags(*species)
return self

def sort(self, key, asc=False):
self._set_sort(key, asc)
return self

def id(self, id):
self._tags = []
self.rating(SearchPost.RATING_ALL)

self._set_id(id)

return self

def __str__(self):
return "Search: tags: %s; matches: %i;" % (self._tags, self._matches)
class Search(object):
"""
Performs the actual transaction with the e621 API
"""

def __init__(self, query):
"""
Initiate properties
"""
self._query = query
self._count = 0

def _execute_query(self):
"""
Perform API call and treat the response
"""
pass
@@ -1,26 +1,38 @@
def _add_tag(tags, tag):
tag = _clean_tag(tag)
"""
Helper functions frequently used by the module's classes
"""

if ':' not in tag:
tags.append(tag)
return tags

parts = tag.split(':')
if len(parts) != 2:
return tags
def add_tag(tags, tag):
"""
Add a tag to a given tag list
"""

key = parts[0]
value = parts[1]
# Format tag to e621 standards
tag = clean_tag(tag)

for i in range(len(tags)):
if key in tags[i]:
# Retrieve the tag 'key' if any
key = None
if ':' in tag:
key = tag.split(':')[0]
key = '%s:' % key

for i, item in enumerate(tags):
# Look for simple duplicates
if item == tag:
return tags

# Look for key duplicates
if key and key in item:
tags[i] = tag
return tags

tags.append(tag)
return tags


def _clean_tag(tag):
def clean_tag(tag):
"""
Format tag to match e621 format
"""
tag = tag.replace(' ', '_')
return tag
@@ -1,16 +1,20 @@
"""
e621apy setup file
"""

from setuptools import setup
from setuptools import find_packages

setup(
name='e621apy',
description='A python layer for the e621 api',
url='http://github.com/Hastegan/e621-apy',
version='0.1',
author='Hastegan',
author_email='hastegan@durbatuluk.net',
licence='',
platforms=['any'],
packages=find_packages(),
include_package_data=True,
download_url='',
name='e621apy',
description='A python layer for the e621 api',
url='http://github.com/Hastegan/e621-apy',
version='0.1',
author='Hastegan',
author_email='hastegan@durbatuluk.net',
licence='',
platforms=['any'],
packages=find_packages(),
include_package_data=True,
download_url='',
)