def logprowork(log_path, log_content, withtime='y'):
        """Universal work log save

        @@API that allows external calls
        Notice: If here print series fucntion raise UnicodeEncodeError, it must web page 
        include emoji symbol encode title when use prettytable to package title info
        :param log_path:    log save path
        :param log_content: log save content
        :param withtime:    default parameter, print and save with real time or not
        :return:            none
        """
        # add context to the file use option 'a+'
        # write content may have some not utf8 code, example Japanese
        log_file_ptr = open(log_path, 'a+', encoding='utf-8')

        # select add real time word or not
        if withtime == 'y':
            dataload.logtime_print(log_content)
            # use variable-length argument write word to the log file
            log_file_ptr.write(
                dataload.realtime_logword(dataload.base_time) + log_content +
                '\n')
        else:
            print(log_content)
            log_file_ptr.write(log_content + '\n')
        log_file_ptr.close()
Esempio n. 2
0
    def wca_logprowork(self, logpath, log_content, withtime=True):
        """Universal work log save

        @@API that allows external calls
        Notice: If here print series fucntion raise UnicodeEncodeError, it must web page 
        include emoji symbol encode title when use prettytable to package title info
        :param logpath:     log save path
        :param log_content: log save content
        :param withtime:    default parameter, print and save with real time or not
        :return:            none
        """
        # if log path is none, just print message and return, no log action
        if logpath == None:
            dl.LT_PRINT(log_content)
            return

        # add context to the file use option 'a+'
        # write content may have some not utf8 code, example Japanese
        log_fd = open(logpath, 'a+', encoding='utf-8')

        if withtime == True:
            dl.LT_PRINT(log_content)

            log_content = self.wca_remove_color_chars(
                log_content)  # remove log color chars
            # remove timestamp log color chars
            timestamp = dl.realtime_logword(dl.base_time)
            timestamp = self.wca_remove_color_chars(timestamp)
            timestamp = timestamp[:-1] + ' '  # timestamp has a space in tail

            log_fd.write(timestamp + log_content + '\n')

        else:
            print(log_content)
            log_content = self.wca_remove_color_chars(log_content)
            log_fd.write(log_content + '\n')
        log_fd.close()
Esempio n. 3
0
    def _login_preload(self, aes_file_path):
        """Get user input login info and storage into aes file

        If project directory has no file, you need hand-input login info,
        then program will create new file to storage AES encrypt info to it
        This method use pycrypto, need import external call
        :param aes_file_path:       .aes_crypto_login.ini file path
        :return:                    none
        """
        if os.path.exists(aes_file_path):
            # stable read rows get username and password
            read_aes_file = open(aes_file_path, 'rb+')
            readline_cache = read_aes_file.readlines()  # all line list
            read_aes_file.close()

            # get aes file storage info and split tail '\n'
            aes_info = {
                'iv_param': readline_cache[0][:-1],
                'user_mail': readline_cache[1][:-1],
                'passwd': readline_cache[2][:-1]
            }

            # analysis hash value to string
            username_aes_decrypt_cipher = AES.new(dl.AES_SECRET_KEY,
                                                  AES.MODE_CFB,
                                                  aes_info['iv_param'])
            username = str(
                username_aes_decrypt_cipher.decrypt(
                    aes_info['user_mail'][AES.block_size:]), 'UTF-8')
            password_aes_decrypt_cipher = AES.new(dl.AES_SECRET_KEY,
                                                  AES.MODE_CFB,
                                                  aes_info['iv_param'])
            passwd = str(
                password_aes_decrypt_cipher.decrypt(
                    aes_info['passwd'][AES.block_size:]), 'UTF-8')

            if self.ir_mode == dl.MODE_INTERACTIVE:
                check = dl.LT_INPUT(
                    dl.HL_CY("get user account info ok, check: \n"
                             "[*username] %s\n[*password] %s\n"
                             "Is that correct? (Y/N): " % (username, passwd)))

                # if user judge info are error, delete old AES file and record new info
                if check == 'N' or check == 'n':
                    os.remove(aes_file_path)  # delete old AES file
                    # temporarily enter login information
                    dl.LT_PRINT(
                        dl.BY_CB(
                            "Well, you need hand-input your login data: "))
                    username = dl.LT_INPUT(
                        dl.HL_CY(
                            'enter your pixiv id(mailbox), must be a R18: '))
                    passwd = getpass.getpass(
                        dl.realtime_logword(dl.base_time) +
                        dl.HL_CY('enter your account password: '******'enter your pixiv id(mailbox), must be a R18: '))
            passwd = getpass.getpass(
                dl.realtime_logword(dl.base_time) +
                dl.HL_CY('enter your account password: '******'user', username), ('pass', passwd)]
        getway_data = urllib.parse.urlencode(getway_register).encode(
            encoding='UTF8')

        self.username = username
        self.passwd = passwd
        self.getway_data = getway_data
    def _login_preload(aes_file_path):
        """Get user input login info and storage into aes file

        If project directory has no file, you need hand-input login info,
        then program will create new file to storage AES encrypt info to it
        This method use pycrypto, need import external call
        :param aes_file_path:       .aes_crypto_login.ini file path
        :return:                    username, password, get data
        """
        is_aes_file_existed = os.path.exists(aes_file_path)
        if is_aes_file_existed:
            # stable read rows get username and password
            # read bin file content to a list
            read_aes_file = open(aes_file_path, 'rb+')
            readline_cache = read_aes_file.readlines()  # all line list
            read_aes_file.close()

            read_aes_iv_param_raw = readline_cache[0]  # row 1 is AES IV PARAM
            read_user_mailbox_raw = readline_cache[1]  # row 2 is username
            read_user_passwd_raw = readline_cache[2]  # row 3 is password
            # cut last char (b'\n')
            read_aes_iv_param_raw = read_aes_iv_param_raw[:-1]
            read_user_mailbox_raw = read_user_mailbox_raw[:-1]
            read_user_passwd_raw = read_user_passwd_raw[:-1]

            # analysis hash value to string
            username_aes_decrypt_cipher = AES.new(dataload.AES_SECRET_KEY,
                                                  AES.MODE_CFB,
                                                  read_aes_iv_param_raw)
            username = str(
                username_aes_decrypt_cipher.decrypt(
                    read_user_mailbox_raw[AES.block_size:]), 'UTF-8')
            password_aes_decrypt_cipher = AES.new(dataload.AES_SECRET_KEY,
                                                  AES.MODE_CFB,
                                                  read_aes_iv_param_raw)
            passwd = str(
                password_aes_decrypt_cipher.decrypt(
                    read_user_passwd_raw[AES.block_size:]), 'UTF-8')

            # check username and password
            check = dataload.logtime_input(
                "Read user login information configuration ok, check this: \n"
                "[-> Username] %s\n[-> Password] %s\n"
                "Is that correct? (Y/N): " % (username, passwd))

            # if user judge info are error, delete old AES file and record new info
            if check == 'N' or check == 'n':
                os.remove(aes_file_path)  # delete old AES file
                # temporarily enter login information
                dataload.logtime_print(
                    "Well, you need hand-input your login data: ")
                username = dataload.logtime_input(
                    'Enter your pixiv id(mailbox), must be a R18: ').encode(
                        'utf-8')
                passwd = getpass.getpass(
                    dataload.realtime_logword(dataload.base_time) +
                    'Enter your account password: '******'utf-8')

                generate_aes_iv_param = Random.new().read(
                    AES.block_size)  # generate random aes iv param
                username_cipher = AES.new(dataload.AES_SECRET_KEY,
                                          AES.MODE_CFB, generate_aes_iv_param)
                username_encrypto = generate_aes_iv_param + username_cipher.encrypt(
                    username)
                passwd_cipher = AES.new(dataload.AES_SECRET_KEY, AES.MODE_CFB,
                                        generate_aes_iv_param)
                passwd_encrypto = generate_aes_iv_param + passwd_cipher.encrypt(
                    passwd)

                # create new aes file rewrite it
                write_aes_file = open(aes_file_path, 'wb')
                # write bin value to file with b'\n' to wrap
                write_aes_file.write(generate_aes_iv_param +
                                     b'\n')  # row 1 is iv param
                write_aes_file.write(username_encrypto +
                                     b'\n')  # row 2 is username
                write_aes_file.write(passwd_encrypto +
                                     b'\n')  # row 3 is password
                write_aes_file.close()
            # read info correct, jump out here
            else:
                pass

        # if no AES file, then create new and write md5 value into it
        else:
            dataload.logtime_print(
                "Create new AES encrypt file to storage your username and password: "
            )
            username = dataload.logtime_input(
                'Enter your pixiv id(mailbox), must be a R18: ').encode(
                    'utf-8')
            passwd = getpass.getpass(
                dataload.realtime_logword(dataload.base_time) +
                'Enter your account password: '******'utf-8')

            generate_aes_iv_param = Random.new().read(
                AES.block_size)  # generate random aes iv param
            username_cipher = AES.new(dataload.AES_SECRET_KEY, AES.MODE_CFB,
                                      generate_aes_iv_param)
            username_encrypto = generate_aes_iv_param + username_cipher.encrypt(
                username)
            passwd_cipher = AES.new(dataload.AES_SECRET_KEY, AES.MODE_CFB,
                                    generate_aes_iv_param)
            passwd_encrypto = generate_aes_iv_param + passwd_cipher.encrypt(
                passwd)

            # create new AES file, set write bin bytes mode
            write_aes_file = open(aes_file_path, 'wb')
            # write bin value to file with b'\n' to wrap
            write_aes_file.write(generate_aes_iv_param +
                                 b'\n')  # row 1 is iv param
            write_aes_file.write(username_encrypto +
                                 b'\n')  # row 2 is username
            write_aes_file.write(passwd_encrypto + b'\n')  # row 3 is password
            write_aes_file.close()

        # build data string
        getway_register = [('user', username), ('pass', passwd)]
        getway_data = urllib.parse.urlencode(getway_register).encode(
            encoding='UTF8')

        return username, passwd, getway_data  # return login use 3 elements