-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' -- include crucial file
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |