aboutsummaryrefslogtreecommitdiffstats
path: root/get_images.py
diff options
context:
space:
mode:
authorjwansek <eddie.atten.ea29@gmail.com>2020-10-04 01:49:36 +0100
committerjwansek <eddie.atten.ea29@gmail.com>2020-10-04 01:49:36 +0100
commit55bfe256fb77dd083ab7283d795f8932938e73f1 (patch)
tree29cb800c82dd0d68ebeeb63f6442ff7dbde2d64e /get_images.py
parentb4817b94bd6d4c1e177fe55201bf0da0f335de75 (diff)
downloadyaoi-communism-55bfe256fb77dd083ab7283d795f8932938e73f1.tar.gz
yaoi-communism-55bfe256fb77dd083ab7283d795f8932938e73f1.zip
fixed bug where pixiv links 403'd
Diffstat (limited to 'get_images.py')
-rw-r--r--get_images.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/get_images.py b/get_images.py
index 37becdd..bd1efd3 100644
--- a/get_images.py
+++ b/get_images.py
@@ -85,6 +85,13 @@ def get_num_pages(tags):
else:
return int(int(urllib.parse.parse_qs(page_element.get("href"))["pid"][0]) / (5*8))
+def fix_source_url(url):
+ if "pixiv.net" in url or "pximg.net" in url:
+ if requests.get(url).status_code == 403:
+ return "https://www.pixiv.net/en/artworks/%s" % url.split("/")[-1][:8]
+
+ return url
+
def append_blacklisted(id_):
with open(CONFIG["blacklist"], "a") as f:
f.write(str(id_) + "\n")
@@ -116,13 +123,11 @@ def main(draw_faces = False):
simg = get_image(get_random_searchtag())
except ConnectionError:
logging.warning("Retried since couldn't get source...")
- main()
- return
+ return main()
if id_is_blacklisted(simg.id):
logging.info("Retried, already posted image...")
- main()
- return
+ return main()
append_blacklisted(simg.id)
@@ -159,7 +164,7 @@ def main(draw_faces = False):
y = y + height
pilimg.save("img.png")
- return "img.png", simg.source, text
+ return "img.png", fix_source_url(simg.source), text
if __name__ == "__main__":