Skip to content

Commit

Permalink
Merge branch 'develop' -- include crucial file
Browse files Browse the repository at this point in the history
  • Loading branch information
wwyaiykycnf committed Jun 18, 2014
2 parents 93b1d56 + 6c76d9b commit b31e61e
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions lib/e621_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python

from json import loads
from support import SpoofOpen
from collections import namedtuple
import logging

UPLOAD = namedtuple('Upload', 'url md5 ext')
SPOOF = SpoofOpen()

LIST_BASE = 'https://e621.net/post/index.json?'
TAGS = 'tags='
DATE = ' date:>'
PAGE = '&page='
MAX = '&limit='

def get_posts(search_term, uploaded_after, page_num, max_results):
request = LIST_BASE + \
TAGS + search_term + \
DATE + uploaded_after + \
PAGE + str(page_num) + \
MAX + str(max_results)

log = logging.getLogger('e621_api')
log.debug('search url = ' + request)
results = loads(SPOOF.open(request).read().decode())

uploads = []
for post in results:
uploads.append(UPLOAD(post['file_url'], post['md5'], post['file_ext']))
return uploads

def download(url, filename):
with open(filename, 'wb') as dest:
source = SPOOF.open(url)
dest.write(source.read())

0 comments on commit b31e61e

Please sign in to comment.