<commit_before>import urllib.parse
import os
import subprocess
import sys

from PyQt5 import QtCore, QtGui, QtWidgets

import TinyEpub
import ui_mainwindow
import my_mainwindow
import web_info
import neattxt
import txt2html
import arrange
import strucreat
import epubzip
import messager


class BuilderUI_dbg(ui_mainwindow.Ui_MainWindow):
    """the mainUI for EpubBuilder, contains the signal and.pyqtSlot"""

    def __init__(self):
        super(BuilderUI_dbg, self).__init__()
        # set open method depends on platform
        if sys.platform == "win32":
            self.system_open = os.startfile
            from win32com.shell import shell, shellcon
            mydocument_path = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
            self.txt_folder = mydocument_path + os.sep + 'txt'
            self.epub_folder = mydocument_path + os.sep + 'epub'
        elif sys.platform == "linux":
            self.system_open = lambda path: subprocess.Popen(["xdg-open",path])
            self.txt_folder = os.path.expanduser('~/Documents/txt')
            self.epub_folder = os.path.expanduser('~/Documents/epub')

        self.file_path = ''
        self.bookid = ''
        self.title = ''
        self.author = ''
        self.web_address = ''
        self.chr_pattern = ''
        self.description = ''
        self.cover_byte = b''
        self.cover = QtGui.QPixmap()
        self.mine_type = 'application/x-qt-windows-mime;value=\"FileNameW\"'
        self.image_folder = "./images"
        self.ensure_directory(self.txt_folder, self.epub_folder)
        self.book_info = web_info.BookInfo()
        self.message = messager.statusbar_message
        self.rate = messager.process_message
        self.main_window = my_mainwindow.MyMainWindow()
        self.setupUi(self.main_window)

        self.pushButton_get_info.clicked.connect(self.open_url)
        self.lineEdit_title.textChanged.connect(self.to_bookpage)
        self.pushButton_start_build.clicked.connect(self.build)
        self.pushButton_edit_text.clicked.connect(self.edit_text)
        self.main_window.file_loaded.connect(self.load_file)
        self.radioButton_qidian.clicked.connect(self.choose_site)
        self.radioButton_chuangshi.clicked.connect(self.choose_site)
        self.radioButton_zongheng.clicked.connect(self.choose_site)
        self.message.connect(self.statusbar.showMessage)
        self.rate.connect(self.progressBar.setValue)
        messager.page_opened.connect(self.get_info)
        messager.finished.connect(self.finish_build)
        messager.text_neated.connect(self.reset_progressbar)

    def ensure_directory(self, *dir_list):
        for d in dir_list:
            if not os.path.isdir(d):
                os.makedirs(d)

    @QtCore.pyqtSlot(str)
    def load_file(self, file_path):
        if file_path.endswith(".txt"):
            self.file_path = file_path
            self.title = os.path.basename(os.path.splitext(file_path)[0])
            self.load_text()
        else:
            self.load_epub(file_path)
            self.check_has_txt()
        self.lineEdit_title.setText(self.title)

    @QtCore.pyqtSlot(str)
    def to_bookpage(self, title):
        p = True
        for c in title:
            p = p and (c in "1234567890")
        if p:
            self.bookid = title
            if len(self.bookid) < 8:  # 目前的判断规则没法直接从文件名区别是起点还是纵横，甚至有时候几乎不能自行分清起点和创世
                url = "http://www.qidian.com/Book/%s.aspx" % self.bookid
            else:
                url = "http://chuangshi.qq.com/bk/ls/%s-1.html" % self.bookid  # 警告！网址中的ls是"历史"的含义，虽不影响使用，但是十分危险
        else:
            url = 'http://www.lkong.net/book.php?mod=view&bookname=' + urllib.parse.quote(title)
        self.lineEdit_bookpage.setText(url)

    def choose_site(self):
        sender = self.main_window.sender()
        url = ''
        if sender is self.radioButton_chuangshi:
            url = "http://chuangshi.qq.com/bk/ls/%s-1.html" % self.bookid
        elif sender is self.radioButton_qidian:
            url = "http://www.qidian.com/Book/%s.aspx" % self.bookid
        elif sender is self.radioButton_zongheng:
            url = "http://book.zongheng.com/book/%s.html" % self.bookid
        self.lineEdit_bookpage.setText(url)

    def edit_text(self):
        self.system_open(self.file_path)

    def load_text(self):
        self.pushButton_start_build.setEnabled(True)
        self.pushButton_edit_text.setEnabled(True)

    def load_epub(self, file_path):
        book = TinyEpub.Epub(file_path)
        self.title = book.title
        self.author = book.author
        self.description = book.description
        self.chr_pattern = book.chrpattern<commit_msg>small fix with chuangshi url<commit_after>import urllib.parse
import os
import subprocess
import sys

from PyQt5 import QtCore, QtGui, QtWidgets

import TinyEpub
import ui_mainwindow
import my_mainwindow
import web_info
import neattxt
import txt2html
import arrange
import strucreat
import epubzip
import messager


class BuilderUI_dbg(ui_mainwindow.Ui_MainWindow):
    """the mainUI for EpubBuilder, contains the signal and.pyqtSlot"""

    def __init__(self):
        super(BuilderUI_dbg, self).__init__()
        # set open method depends on platform
        if sys.platform == "win32":
            self.system_open = os.startfile
            from win32com.shell import shell, shellcon
            mydocument_path = shell.SHGetFolderPath(0, shellcon.CSIDL_PERSONAL, None, 0)
            self.txt_folder = mydocument_path + os.sep + 'txt'
            self.epub_folder = mydocument_path + os.sep + 'epub'
        elif sys.platform == "linux":
            self.system_open = lambda path: subprocess.Popen(["xdg-open",path])
            self.txt_folder = os.path.expanduser('~/Documents/txt')
            self.epub_folder = os.path.expanduser('~/Documents/epub')

        self.file_path = ''
        self.bookid = ''
        self.title = ''
        self.author = ''
        self.web_address = ''
        self.chr_pattern = ''
        self.description = ''
        self.cover_byte = b''
        self.cover = QtGui.QPixmap()
        self.mine_type = 'application/x-qt-windows-mime;value=\"FileNameW\"'
        self.image_folder = "./images"
        self.ensure_directory(self.txt_folder, self.epub_folder)
        self.book_info = web_info.BookInfo()
        self.message = messager.statusbar_message
        self.rate = messager.process_message
        self.main_window = my_mainwindow.MyMainWindow()
        self.setupUi(self.main_window)

        self.pushButton_get_info.clicked.connect(self.open_url)
        self.lineEdit_title.textChanged.connect(self.to_bookpage)
        self.pushButton_start_build.clicked.connect(self.build)
        self.pushButton_edit_text.clicked.connect(self.edit_text)
        self.main_window.file_loaded.connect(self.load_file)
        self.radioButton_qidian.clicked.connect(self.choose_site)
        self.radioButton_chuangshi.clicked.connect(self.choose_site)
        self.radioButton_zongheng.clicked.connect(self.choose_site)
        self.message.connect(self.statusbar.showMessage)
        self.rate.connect(self.progressBar.setValue)
        messager.page_opened.connect(self.get_info)
        messager.finished.connect(self.finish_build)
        messager.text_neated.connect(self.reset_progressbar)

    def ensure_directory(self, *dir_list):
        for d in dir_list:
            if not os.path.isdir(d):
                os.makedirs(d)

    @QtCore.pyqtSlot(str)
    def load_file(self, file_path):
        if file_path.endswith(".txt"):
            self.file_path = file_path
            self.title = os.path.basename(os.path.splitext(file_path)[0])
            self.load_text()
        else:
            self.load_epub(file_path)
            self.check_has_txt()
        self.lineEdit_title.setText(self.title)

    @QtCore.pyqtSlot(str)
    def to_bookpage(self, title):
        p = True
        for c in title:
            p = p and (c in "1234567890")
        if p:
            self.bookid = title
            if len(self.bookid) < 8:  # 目前的判断规则没法直接从文件名区别是起点还是纵横，甚至有时候几乎不能自行分清起点和创世
                url = "http://www.qidian.com/Book/%s.aspx" % self.bookid
            else:
                url = "http://chuangshi.qq.com/bk/ls/%s.html" % self.bookid  # 警告！网址中的ls是"历史"的含义，虽不影响使用，但是十分危险
        else:
            url = 'http://www.lkong.net/book.php?mod=view&bookname=' + urllib.parse.quote(title)
        self.lineEdit_bookpage.setText(url)

    def choose_site(self):
        sender = self.main_window.sender()
        url = ''
        if sender is self.radioButton_chuangshi:
            url = "http://chuangshi.qq.com/bk/ls/%s.html" % self.bookid
        elif sender is self.radioButton_qidian:
            url = "http://www.qidian.com/Book/%s.aspx" % self.bookid
        elif sender is self.radioButton_zongheng:
            url = "http://book.zongheng.com/book/%s.html" % self.bookid
        self.lineEdit_bookpage.setText(url)

    def edit_text(self):
        self.system_open(self.file_path)

    def load_text(self):
        self.pushButton_start_build.setEnabled(True)
        self.pushButton_edit_text.setEnabled(True)

    def load_epub(self, file_path):
        book = TinyEpub.Epub(file_path)
        self.title = book.title
        self.author = book.author
        self.description = book.description
        self.chr_pattern = book.chrpattern
{'fraction_non_alphanumeric': 0.10748111099287007, 'fraction_numerical': 0.004469511546238161, 'mean_word_length': 2.5158997381219605, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2682272', 'n_tokens_mistral': 3203, 'n_tokens_neox': 3135, 'n_words': 477}