def _download_pages(self): c_page = 0 for chapter in sorted(self.chapters, key=float): self._bookmarks[chapter] = [] pages = self._pages[chapter] logger.debug(f"download: chapter {chapter}") for file in self.api.download_chapter(chapter, self.manga_id, pages): self.chek_running() c_page += 1 logger.debug(f"download: page {c_page}/{self._pages_count}") self._bookmarks[chapter].append(file) self.set_status("downloading chapter" + str(chapter), c_page / self._pages_count / 2)
def run(self): try: self.__class__._current_downloads.append(self) logger.info(f"download: " + self.task_id) self.info = self.api.get_info(self.manga_id) self.chek_running() logger.debug("download: getting pages") self._pages_count, self._pages = self._get_pages() self.chek_running() logger.debug("download: downloading pages") self._download_pages() self.chek_running() logger.debug("download: merging pdf") self._merge_pages() self.chek_running() if self.OUT_FILE: self.set_status("finished", 1, self.OUT_FILE) else: self.set_status("finished", 1) logger.info(f"download: finished " + self.task_id) # self._remove() except ClosedThread: return
def mergeBookmarks(bookmarks: dict, out_file: str): pdf = FPDF(orientation="P", unit="pt", format="A4") for y, (chapter, files) in enumerate(bookmarks.items()): files.sort( key=lambda file: int( re.search(r"\d+", os.path.splitext(os.path.split(file)[1])[0])[0] ) ) for i, imagef in enumerate(files): logger.debug( f"pdf: adding file {i + 1}/{len(files)} of chapter {y + 1}/{len(bookmarks.items())}" ) try: with Image.open(imagef) as image: if image.width > image.height: pdf.add_page("vertical") pdf.image(imagef, x=0, y=00, w=842, h=596) else: tilled = tile(imagef) for image in tilled: pdf.add_page() try: if stretch or len(tilled) == 1: pdf.image(image, x=0, y=00, h=842, w=596) else: pdf.image(image, x=0, y=00, w=596) # h=842, except Exception as e: logger.error( f"pdf: failed to add image {image} to pdf, a blank page is added" ) except OSError as e: pdf.add_page() yield min(i / len(files), 0.9) yield 0.9 pdf.output(out_file, "F")
import logging import requests import json from myLog import logger logger.setLevel(logging.INFO) logger.setLevel(logging.DEBUG) logger.debug("hallo") # r = requests.get('https://api.github.com/events') # r = requests.get('https://heise.de') # r = requests.get('http://*****:*****@172.28.128.3:8080/me/configure') # r = requests.get( # 'http://*****:*****@172.28.128.3:8080/api/json?depth=2&pretty=true') # r = requests.get( # 'http://*****:*****@172.28.128.3:8080/me/api/json/?depth=2&pretty=true') # r = requests.get( # 'http://*****:*****@172.28.128.3:8080/me/api/json/?pretty=true') r = requests.get('http://*****:*****@172.28.128.3:8080/me/api/xml') # r = requests.get('http://*****:*****@172.28.128.3:8080/systemInfo') # ?tree=artifacts[*] # r = requests.get( # 'http://*****:*****@172.28.128.3:8080/me/api/json?tree=jenkins.security.ApiTokenProperty[*[*]]') logger.debug(r.text) logger.info(r.encoding) logger.info(r.status_code) logger.info(r.raise_for_status)
import myLog import time from myLog import logger myLog.setUniqueLogFile("helloProg") logger.info("program starting") print("hello") name = input("what is your name?\n") logger.debug(f"Name read: {name}") print(f"Hello {name}, my name is bot") logger.info("program done")