Skip to content

Commit

Permalink
fix 4
Browse files Browse the repository at this point in the history
  • Loading branch information
silicWulf committed Jan 14, 2017
1 parent 02662f2 commit d0f9d3f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -4,7 +4,7 @@ esto is an easy-to-use e621 API wrapper, with a goal of covering the entirety of

## Functions (0.0.1)

As of 0.0.1, the module has two simple functions: getting a file object, and downloading a file object automatically, both accepting tags as parameters.
As of 0.0.1, the module has three simple functions: getting a file object, downloading a file object automatically, and resolving a post with a given id, all accepting tags as parameters.

In addition, the module currently uses the `requests` module to post requests to the API. In the future the `requests` module will not be required.

Expand Down
Binary file added esto/__pycache__/esto.cpython-35.pyc
Binary file not shown.
21 changes: 16 additions & 5 deletions esto/esto.py
Expand Up @@ -41,7 +41,14 @@ def __init__(self,message):

e6url = "https://e621.net/post/index.json?limit=1&tags="

def _ret(tags):
def _retid(url):
req = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'})
jsonreq = json.loads(req.text)
for i in jsonreq:
pornobj = e621File(str(i['id']), i['tags'].split(' '), i['description'], str(i['creator_id']), str(i['author']), int(i['change']), i['source'], int(i['score']), int(i['fav_count']), i['md5'], str(i['file_size']), i['file_url'], i['file_ext'], i['preview_url'], i['preview_width'], i['preview_height'], i['sample_url'], i['sample_width'], i['sample_height'], i['rating'], i['status'], i['width'], i['height'], i['has_comments'], i['has_notes'], i['has_children'], i['children'], i['parent_id'], i['artist'], i['source'])
return pornobj

def _rettags(tags):
if type(tags) is list:
taglist = '+'.join(tags)
elif type(tags) is str:
Expand All @@ -50,15 +57,19 @@ def _ret(tags):
raise UnsupportedType("the given var type is not supported, must be either list or str")
url = e6url + taglist
req = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'})
jsonreq = json.reads(req.text)
jsonreq = json.loads(req.text)
for i in jsonreq:
pornobj = e621File(str(i['id'])), i['tags'].split(' '), i['description'], str(i['creator_id']), str(i['author']), int(i['change']), i['source'], int(i['score']), int(i['fav_count']), i['md5'], str(i['file_size']), i['file_url'], i['file_ext'], i['preview_url'], i['preview_width'], i['preview_height'], i['sample_url'], i['sample_width'], i['sample_height'], i['rating'], i['status'], i['width'], i['height'], i['has_comments'], i['has_notes'], i['has_children'], i['children'], i['parent_id'], i['artists'], i['sources'])
pornobj = e621File(str(i['id']), i['tags'].split(' '), i['description'], str(i['creator_id']), str(i['author']), int(i['change']), i['source'], int(i['score']), int(i['fav_count']), i['md5'], str(i['file_size']), i['file_url'], i['file_ext'], i['preview_url'], i['preview_width'], i['preview_height'], i['sample_url'], i['sample_width'], i['sample_height'], i['rating'], i['status'], i['width'], i['height'], i['has_comments'], i['has_notes'], i['has_children'], i['children'], i['parent_id'], i['artist'], i['source'])
return pornobj
def resolveid(id):
url = "https://e621.net/post/show.json?id=" + id
pornobj = _retid(url)
return pornobj
def getdata(tags):
pornobj = _ret(tags)
pornobj = _rettags(tags)
return pornobj
def downloadfile(tags,filename):
pornobj = _ret(tags)
pornobj = _rettags(tags)
file = open(filename, "w")
file.write(requests.get(pornobj.file_url, headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'}))
file.close()

0 comments on commit d0f9d3f

Please sign in to comment.