From d0f9d3fbf81870bfab4e86838c4e8d1058dfeb10 Mon Sep 17 00:00:00 2001 From: silicWulf Date: Sat, 14 Jan 2017 14:57:52 -0500 Subject: [PATCH] fix 4 --- README.md | 2 +- esto/__pycache__/esto.cpython-35.pyc | Bin 0 -> 3170 bytes esto/esto.py | 21 ++++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 esto/__pycache__/esto.cpython-35.pyc diff --git a/README.md b/README.md index 4515b7a..4a8de6a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/esto/__pycache__/esto.cpython-35.pyc b/esto/__pycache__/esto.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6b5216e5d1fdc6a5c7bf03bbfd8f175195ca2537 GIT binary patch literal 3170 zcmd5;U2hXd6rJ_A9h*QB0wEzRpT#P*2_ZogC`HiHijqDA1hQ1EmfcCb#@;nEV-hSP zRisjXL4QOa`*-HGPkrk%FYUQ^ZIedo3s0=Q_ntFz=VNDg&Yk&Mt@8KJ!{_g&g!oe& zxN^W>8VWwj|fDt$Z7GWpD<;bdjeX?&H=oju3Ah@m2^AAj1GO%K$XT05s14w7>wg z$N;p&0JO{iw88*%iUDYq0cec@=n)2>(+oh5G5|fs0Ca`{=qv-!IR>D|8Gz0+06oC~ z^dtk&1qPs}7=SJ^09|4LdYS>~GK16fQa9_)Mt#|4qR{4yzpd?5D0QHszKN39Rstn` zlPC|>1%F`LiL!;D?Z?~F7IZRDfwXxYBud)ymjBudl0j^2wim8}<3)Hn8cJJYI8faY zlDo!E^_6@b$sLc1Yh$t#g{EzfjA>g&+ihbj+VAzz8HH9yIE}20*eI}|d=tgnn40m; zK-+v8RTx!Q+rGvWdp#K&ZOg>s#7J$^igwfum5gmE7^8CEM}eWIFZ#+v8qJF7W9#}E zo71wprLy?8RE|uZOo2?1Oo>dHOoa@#piosZH8MxYOp`fE<`|h7GP7jn$Q&m#Pv!)f zlVldioFcPGhIWNIO=g)4eecSJ`CX`UaPQAG+euG0w~}3>5)<@$O{q=t!8H1BY{~PY zI5M6`v(~p^gj4?L-|*OY7dFQIZqVNJyx8wa&$AWJ>m}g;@6)qY&wDlSyJ?NOfRTCH z2h4dYqb*G9stHsb<{zyR(@$eP==T$4WccJwUk21EUF7Lzv7mP}5sUFYacr?Cwf47V zJ)_PdLe?*tG)zUW2M^!Z8uK&ipQ3bF49+j5M-W-&wK6NKjcQSPg zsXLXr#ndgO?sV#wQ+FnHZtBja?p*55rw&uzUlw}>@#;763~6bzeqrOi^Z9$n9o{u< z>261_W$eE8m22=tyODMwZ0_VUzvA`=+PE*ID)nH{5xg45Mz>Z>}}2x|bjOK@^)rw{N-M$3}Kt6u3Wby3gH}tKLm-weH^QL!h6@ z7mp&-TwA@-SY3B7Kl<*;;~%bIte4V#D1(JT@_}6r5kMg<4qqA3!G`0L zCPX8Z3+#7?f(l|ELxpsF$!}O^N73Vd5+5+$B`vhgC4C$v@;fRrQmvvyT_;0X-{ymE zqGdhD>zba4C<7{5VVk4F(&2TkhRIG$pAc12|C$aLwAj2gsbWO@GPCY{u8^tL Hs@Z=50}-Ke literal 0 HcmV?d00001 diff --git a/esto/esto.py b/esto/esto.py index 70ec3ed..c7de7a0 100644 --- a/esto/esto.py +++ b/esto/esto.py @@ -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: @@ -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() \ No newline at end of file