def _select(booklink, **kwargs): if booklink.isdigit(): # this is book id with wrapper(booklink) as d: booklink = d[K_URL] url = booklink.split('/')[2] mod_name = url.replace('.', '_') mod = importlib.import_module(NOVELWEBSITE + '.' + mod_name) cls_mydl = getattr(mod, 'mydl') mydl = cls_mydl(url_check(booklink)) # this is for debug, append debug argv to class for k, v in kwargs.items(): setattr(mydl, k , v) return mydl
def convert(id_, *argv, **kwarg): '''Usage: n convert <id> txt|aozora|epub|mobi txt raw -> txt aozora raw -> aozora txt epub aozora txt -> epub mobi epub -> mobi e.g. n c 0 t e''' with wrapper(id_) as d: if not argv: argv = 'taem' for ext in argv: if 'txt'.startswith(ext): raw2text(d) elif 'aozora'.startswith(ext): raw2aozora(d) elif 'epub'.startswith(ext): aozora2epub(d) elif 'mobi'.startswith(ext): epub2mobi(d)
def push(*argv, **kwarg): '''Usage n send <id> copy the epub to MTP device. e.g. n push 0 required: need global settings, mtp_device and mtp_copyto mtp_device: the name of MTP device. ex. Pixel 3 XL mtp_copyto: the path we copy books to, use the internal storage. ex Download\aa\bb''' sample = pathlib.Path('lib\cmds\shell\mtptransferSample.ps1') content = sample.read_text() ps1 = pathlib.Path('tmp.ps1') heads = '''param([string]$deviceName = '{}', [System.IO.FileInfo]$copyFrom = '{}', [string]$copyTo = '{}') ''' for id_ in argv: with wrapper(id_) as d: epub = pathlib.Path(d[K_DIR]) epub = epub / epub.name epub = epub.with_suffix('.epub') with ps1.open('w', encoding='utf-8') as f: f.write(u'\ufeff') # Write window BOM f.write(heads.format( GLOBAL.mtp_device, epub, GLOBAL.mtp_copyto, )) f.write(content) cmd = f'powershell -ExecutionPolicy Bypass -file {ps1}' r = run(cmd) ps1.unlink()
def folder(id_=None, *argv, **kwarg): '''n browser <id> open the book folder.''' with wrapper(id_) as d: _open_folder(d[K_DIR])
def browser(id_=None, *argv, **kwarg): '''n browser <id> open the book url.''' with wrapper(id_) as d: _open_url(d[K_URL])