From 4b22e646bf7afbf6292b02a908477007c02c9b53 Mon Sep 17 00:00:00 2001 From: jwansek Date: Sat, 20 Feb 2021 15:11:14 +0000 Subject: changed the getting sauces system --- .gitignore | 0 .gitmodules | 0 LICENSE | 0 bot.py | 2 +- exampleconfig.json | 0 fonts/BadScript-Regular.ttf | Bin fonts/Caveat-Bold.ttf | Bin fonts/Caveat-Regular.ttf | Bin fonts/DancingScript-VariableFont_wght.ttf | Bin fonts/Kalam-Regular.ttf | Bin fonts/Roboto-Bold.ttf | Bin fonts/Satisfy-Regular.ttf | Bin fonts/Yellowtail-Regular.ttf | Bin get_images.py | 22 +++++++++++++++++++--- readme.md | 0 requirements.txt | 0 texts/quotes.txt | 0 texts/short.txt | 0 utils.py | 0 19 files changed, 20 insertions(+), 4 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .gitmodules mode change 100644 => 100755 LICENSE mode change 100644 => 100755 bot.py mode change 100644 => 100755 exampleconfig.json mode change 100644 => 100755 fonts/BadScript-Regular.ttf mode change 100644 => 100755 fonts/Caveat-Bold.ttf mode change 100644 => 100755 fonts/Caveat-Regular.ttf mode change 100644 => 100755 fonts/DancingScript-VariableFont_wght.ttf mode change 100644 => 100755 fonts/Kalam-Regular.ttf mode change 100644 => 100755 fonts/Roboto-Bold.ttf mode change 100644 => 100755 fonts/Satisfy-Regular.ttf mode change 100644 => 100755 fonts/Yellowtail-Regular.ttf mode change 100644 => 100755 get_images.py mode change 100644 => 100755 readme.md mode change 100644 => 100755 requirements.txt mode change 100644 => 100755 texts/quotes.txt mode change 100644 => 100755 texts/short.txt mode change 100644 => 100755 utils.py diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.gitmodules b/.gitmodules old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/bot.py b/bot.py old mode 100644 new mode 100755 index 3c8f6e0..7161ce5 --- a/bot.py +++ b/bot.py @@ -1,5 +1,5 @@ import os -os.chdir("/root/yaoi-communism") +os.chdir("/home/eden/yaoi-communism") from twython import Twython import get_images diff --git a/exampleconfig.json b/exampleconfig.json old mode 100644 new mode 100755 diff --git a/fonts/BadScript-Regular.ttf b/fonts/BadScript-Regular.ttf old mode 100644 new mode 100755 diff --git a/fonts/Caveat-Bold.ttf b/fonts/Caveat-Bold.ttf old mode 100644 new mode 100755 diff --git a/fonts/Caveat-Regular.ttf b/fonts/Caveat-Regular.ttf old mode 100644 new mode 100755 diff --git a/fonts/DancingScript-VariableFont_wght.ttf b/fonts/DancingScript-VariableFont_wght.ttf old mode 100644 new mode 100755 diff --git a/fonts/Kalam-Regular.ttf b/fonts/Kalam-Regular.ttf old mode 100644 new mode 100755 diff --git a/fonts/Roboto-Bold.ttf b/fonts/Roboto-Bold.ttf old mode 100644 new mode 100755 diff --git a/fonts/Satisfy-Regular.ttf b/fonts/Satisfy-Regular.ttf old mode 100644 new mode 100755 diff --git a/fonts/Yellowtail-Regular.ttf b/fonts/Yellowtail-Regular.ttf old mode 100644 new mode 100755 diff --git a/get_images.py b/get_images.py old mode 100644 new mode 100755 index 817b9c1..9d25599 --- a/get_images.py +++ b/get_images.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from PIL import Image, ImageDraw +from lxml.html import parse from io import StringIO from lxml import etree import requests @@ -85,10 +86,21 @@ def get_num_pages(tags): else: return int(int(urllib.parse.parse_qs(page_element.get("href"))["pid"][0]) / (5*8)) +def check_pixiv_404(url): + text = requests.get(url).text + return text[text.find("") + 7 : text.find("")] == "イラストコミュニケーションサービス[pixiv]" + def fix_source_url(url): - if "pixiv.net" in url or "pximg.net" in url: - return "https://www.pixiv.net/en/artworks/%s" % url.split("/")[-1][:8] - return url + parsed = urllib.parse.urlparse(url) + if parsed.netloc == "www.pixiv.net": + return "https://www.pixiv.net/en/artworks/" + urllib.parse.parse_qs(parsed.query)["illust_id"][0] + elif parsed.netloc in ["bishie.booru.org", "www.secchan.net"]: + return ConnectionError("Couldn't get source") + elif "pximg.net" in parsed.netloc or "pixiv.net" in parsed.netloc: + return "https://www.pixiv.net/en/artworks/" + parsed.path.split("/")[-1][:8] + elif parsed.netloc == "twitter.com": + return url.replace("twitter.com", "nitter.eda.gay") + return url def append_blacklisted(id_): with open(CONFIG["blacklist"], "a") as f: @@ -127,6 +139,10 @@ def main(draw_faces = False): logging.info("Retried, already posted image...") return main() + if check_pixiv_404(fix_source_url(simg.source)): + logging.warning("Skipping since pixiv linked 404'd") + return main() + append_blacklisted(simg.id) with DownloadedImage(simg.imurl) as impath: diff --git a/readme.md b/readme.md old mode 100644 new mode 100755 diff --git a/requirements.txt b/requirements.txt old mode 100644 new mode 100755 diff --git a/texts/quotes.txt b/texts/quotes.txt old mode 100644 new mode 100755 diff --git a/texts/short.txt b/texts/short.txt old mode 100644 new mode 100755 diff --git a/utils.py b/utils.py old mode 100644 new mode 100755 -- cgit v1.2.3