Example #1
0
    def __init__(self,
                 username: str = 'wenku8toepub',
                 password: str = 'wenku8toepub',
                 proxy: str = None,
                 **kwargs):
        # api格式
        # 参数1:id千位开头
        # 参数2:id
        self.api = "https://www.wenku8.net/novel/%s/%d/"
        self.api_info = "https://www.wenku8.net/book/%d.htm"
        # self.api_img = "http://img.wkcdn.com/image/%s/%d/%ds.jpg"
        self.api_img = "https://img.wenku8.com/image/%s/%d/%ds.jpg"
        self.img_splits = [
            'http://pic.wenku8.com/pictures/',
            'http://pic.wkcdn.com/pictures/',
            'http://picture.wenku8.com/pictures/',
            'https://pic.wenku8.com/pictures/',
            'https://pic.wkcdn.com/pictures/',
            'https://picture.wenku8.com/pictures/'
        ]
        self.api_login = '******'
        self.api_search_1 = 'http://www.wenku8.net/modules/article/search.php?searchtype=articlename&searchkey=%s'
        self.api_search_2 = 'http://www.wenku8.net/modules/article/search.php?searchtype=author&searchkey=%s'
        self.api_txt = 'http://dl.wenku8.com/down.php?type=txt&id=%d'
        self.cookies = ''
        self.cookie_jar = None
        self.book = epub.EpubBook()
        self.thread_img_pool = []
        self.thread_pool = []
        # 用于章节排序的文件名
        self.sum_index = 0
        # 目录管理
        self.toc = []
        # 主线
        self.spine = ['cover', 'nav']
        # 当前章节
        self.chapters = []
        self.book_id: int = 0
        self.image_size = None
        self.image_count = 0

        self.proxy: str = proxy

        self.lock = threading.Lock()

        self.logger = kwargs.get('logger', None)
        if self.logger is None:
            self.logger = get_logger(__name__)

        # 搜索用账号
        self.username, self.password = username, password

        # 解决结束程序的进度保存问题
        self.running: bool = False
        self.watcher = Wenku8ToEpub.Watcher(on_exit=self.on_exit)

        # 是否使用原书名做文件名
        self.raw_book_name: bool = kwargs.get('raw_book_name', False)
Example #2
0
import json
import os
import time
import requests
from ws4py.client.threadedclient import WebSocketClient
from base_logger import get_logger

target = 'ws://localhost:10086/'
logger = get_logger(__name__)


class MyClient(WebSocketClient):
    def opened(self):
        pass

    def closed(self, code, reason=None):
        pass

    def received_message(self, resp):
        logger.info(str(resp))


def main():
    ws = MyClient(target)
    ws.connect()
    time.sleep(0.1)
    time.sleep(0.1)
    ws.close()
    time.sleep(0.1)

Example #3
0
 def _get_logger(self):
     """
     get logger for File/Stream handlers
     """
     create_logger(self.log_dir, self.experiment)
     return get_logger()
Example #4
0
                    中间用空格隔开。此项请放在最后。
    -t              只获取文字,忽略图片,但是图像远程链接仍然保留在文中。
                    此开关默认关闭,即默认获取图片。
    -i              显示该书信息。
    -s search_key   按照关键词搜索书籍。
    -p proxy_url    使用代理。(*_proxy等环境变量同样有效。)
    -b              把生成的epub文件直接从标准输出返回。此时list长度应为1。
    -h              显示本帮助。
    -r              不剔除特殊符号而使用原书名作为文件名保存。

    Example:        wk2epub -t 2541
    About:          https://github.com/chiro2001/Wenku8ToEpub
    Version:        2021/12/03 10:53 AM
'''

logger = get_logger()

if __name__ == '__main__':
    try:
        _opts, _args = getopt.getopt(sys.argv[1:], '-h-t-b-i-r-os:p:', [])
    except getopt.GetoptError as e:
        logger.error(f'参数解析错误: {e}')
        sys.exit(1)
    _fetch_image = True
    _bin_mode = False
    _show_info = False
    _print_help = True
    _run_mode = 'download'
    _search_key: str = None
    _proxy: str = None
    _raw_book_name: bool = False