Example #1
0
    def get_base_info(self,
                      base_info=False,
                      introduction_info=False,
                      props_info=False,
                      out_xls=False,
                      s_sent=False,
                      acc_nature=0):
        """
        账号基本信息获取
        By:CyiceK
        有bug请反馈
        :param acc_nature: 小/大号
        :param s_sent: 是否发送到Server酱
        :param out_xls: 是否输出为Excel表格
        :param base_info: 是否读取主页面的基本信息
        :param introduction_info: 是否读取介绍的基本信息
        :param props_info: 是否读取道具的基本信息-扫荡券
        :return: acc_info_dict
        """
        # 笨方法转化时间戳"%Y-%m-%d-%H-%M-%S"
        date_start = datetime.datetime(1899, 12, 30)
        date_now = datetime.datetime.now()
        delta = date_now - date_start
        # 时间戳
        date_1900 = float(delta.days) + (float(delta.seconds) / 86400)
        # 日期
        date = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")

        acc_info_dict = {
            "dengji": 'None',
            "jianjie_name": 'None',
            "tili": 'None',
            "mana": 'None',
            "baoshi": 'None',
            "jianjie_zhanli": 'None',
            "jianjie_hanghui": 'None',
            "jianjie_id": 'None',
            "zhanghao": self.account,
            "group": ','.join(get_all_group(self.account)),
            "saodangquan": 'None',
            "date": date,
        }
        acc_info_list = []
        self.lock_home()
        if base_info:
            time.sleep(2)
            self.lock_home()
            screen_shot = self.getscreen()
            # 体力 包括/
            acc_info_dict["tili"] = self.ocr_center(243, 6, 305, 22, screen_shot=screen_shot, size=2.0) \
                .replace('=', '').replace('-', '').replace('一', '').replace('_', '')
            # 等级
            acc_info_dict["dengji"] = make_it_as_number_as_possible(
                self.ocr_center(29,
                                43,
                                60,
                                67,
                                screen_shot=screen_shot,
                                size=2.0))
            # mana
            acc_info_dict["mana"] = make_it_as_number_as_possible(
                self.ocr_center(107, 54, 177, 76, screen_shot=screen_shot, size=2.0) \
                    .replace(',', '').replace('.', ''))
            # 宝石
            acc_info_dict["baoshi"] = make_it_as_number_as_possible(
                self.ocr_center(258, 52, 306, 72, screen_shot=screen_shot, size=2.0) \
                    .replace(',', '').replace('.', ''))
        if introduction_info:
            self.lock_img(ZHUCAIDAN_BTN["bangzhu"],
                          elseclick=[(871, 513)])  # 锁定帮助
            # 去简介
            self.lock_no_img(ZHUCAIDAN_BTN["jianjie"], elseclick=[(382, 230)])
            self.lock_img(ZHUCAIDAN_BTN["jianjie_L"],
                          elseclick=[(382, 230)])  # 锁定简介
            screen_shot = self.getscreen()
            acc_info_dict["jianjie_name"] = self.ocr_center(
                608, 151, 879, 178, screen_shot=screen_shot, size=2.0)
            acc_info_dict["dengji"] = make_it_as_number_as_possible(
                self.ocr_center(702,
                                184,
                                785,
                                205,
                                screen_shot=screen_shot,
                                size=2.0))
            acc_info_dict["jianjie_zhanli"] = make_it_as_number_as_possible(
                self.ocr_center(702,
                                214,
                                786,
                                235,
                                screen_shot=screen_shot,
                                size=2.0))
            acc_info_dict["jianjie_hanghui"] = self.ocr_center(
                703, 243, 918, 266, screen_shot=screen_shot, size=2.0)
            acc_info_dict["jianjie_id"] = make_it_as_number_as_possible(
                self.ocr_center(598,
                                415,
                                768,
                                435,
                                screen_shot=screen_shot,
                                size=1.2))
        if props_info:
            self.lock_img(ZHUCAIDAN_BTN["bangzhu"],
                          elseclick=[(871, 513)])  # 锁定帮助
            # 去道具
            self.lock_no_img(ZHUCAIDAN_BTN["daoju"], elseclick=[(536, 159)])
            self.lock_img(ZHUCAIDAN_BTN["daojuyilan"],
                          elseclick=[(536, 159)])  # 锁定道具一览
            screen_shot = self.getscreen()
            self.click_img(screen=screen_shot,
                           img="img/zhucaidan/saodangquan.bmp")
            time.sleep(2)
            screen_shot = self.getscreen()
            acc_info_dict["saodangquan"] = self.get_daoju_number(
                screen_shot, must_int=False)
        acc_info_list.append(acc_info_dict)
        self.lock_home()
        # 表格数据整理和转换
        if out_xls:
            # 将字典列表转换为DataFrame
            pf = pd.DataFrame(list(acc_info_list))
            # 指定字段顺序
            order = [
                'dengji', 'jianjie_name', 'tili', 'mana', 'baoshi',
                'jianjie_zhanli', 'jianjie_hanghui', 'jianjie_id', 'zhanghao',
                'group', 'saodangquan', 'date'
            ]
            pf = pf[order]
            # 将列名替换为中文
            columns_map = {
                'dengji': '等级',
                'jianjie_name': '名字',
                'tili': '体力',
                'mana': '玛娜数量',
                'baoshi': '宝石数量',
                'jianjie_zhanli': '全角色战力',
                'jianjie_hanghui': '所属行会',
                'jianjie_id': '玩家ID',
                'zhanghao': '账号',
                'group': '所在组',
                'saodangquan': '所拥有的扫荡券',
                'date': '录入日期',
            }
            pf.rename(columns=columns_map, inplace=True)

            if acc_nature == 0:
                # 小号/农场号输出格式
                xls_path = 'xls/%s-pcr_farm_info.xlsx' % self.today_date
            elif acc_nature == 1:
                # 大号统一文件格式
                xls_path = 'xls/pcr_farm_info.xlsx'
            else:
                # 乱输入就这样的格式
                xls_path = 'xls/%s-pcr_farm_info.xlsx' % self.today_date

            # 将空的单元格替换为空字符
            pf.fillna('', inplace=True)
            # 判断文件是否存在
            if not os.path.exists(xls_path):
                # 输出
                # 指定生成的Excel表格名称
                file_path = pd.ExcelWriter(xls_path, engine='openpyxl')
                pf.to_excel(file_path,
                            engine='openpyxl',
                            encoding='utf-8',
                            index=False)
                # 保存表格
                file_path.save()
                return acc_info_dict
            # 多进程怎么加锁QAQ

            # 保存表格
            index = len(list(acc_info_list))  # 获取需要写入数据的行数
            workbook = openpyxl.load_workbook(xls_path)  # 打开表格
            sheets = workbook.sheetnames  # 获取表格中的所有表格
            worksheet = workbook[sheets[0]]  # 获取表格中所有表格中的的第一个表格
            rows_old = worksheet.max_row  # 获取表格中已存在的数据的行数
            for i in range(0, index):
                for j in range(0, len(list(acc_info_list)[i])):
                    # 追加写入数据,注意是从i+rows_old行开始写入
                    worksheet.cell(row=i + 1 + rows_old, column=1 +
                                   j).value = list(acc_info_dict.values())[j]
            workbook.save(xls_path)  # 保存表格

        return acc_info_dict
Example #2
0
    def get_base_info(self,
                      base_info=False,
                      introduction_info=False,
                      props_info=False,
                      char_info=False,
                      out_xls=False,
                      s_sent=False,
                      acc_nature=0):
        """
        账号基本信息获取
        By:CyiceK
        有bug请反馈
        :param acc_nature: 小/大号
        :param s_sent: 是否发送到Server酱
        :param out_xls: 是否输出为Excel表格
        :param base_info: 是否读取主页面的基本信息
        :param introduction_info: 是否读取介绍的基本信息
        :param props_info: 是否读取道具的基本信息-扫荡券
        :param char_info: 是否记录三星角色
        :return: acc_info_dict
        """
        # 笨方法转化时间戳"%Y-%m-%d-%H-%M-%S"
        date_start = datetime.datetime(1899, 12, 30)
        date_now = datetime.datetime.now()
        delta = date_now - date_start
        # 时间戳
        date_1900 = float(delta.days) + (float(delta.seconds) / 86400)
        # 日期
        date = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")

        acc_info_dict = {
            "dengji": 'None',
            "jianjie_name": 'None',
            "tili": 'None',
            "mana": 'None',
            "baoshi": 'None',
            "jianjie_zhanli": 'None',
            "jianjie_hanghui": 'None',
            "jianjie_id": 'None',
            "zhanghao": self.account,
            "group": ','.join(get_all_group(self.account)),
            "charlist": 'None',
            "saodangquan": 'None',
            "date": date,
        }
        acc_info_list = []
        self.lock_home()
        if base_info:
            time.sleep(2)
            self.lock_home()
            screen_shot = self.getscreen()
            # 体力 包括/
            A, B = self.ocr_A_B(243, 6, 305, 22, screen_shot=screen_shot)
            acc_info_dict["tili"] = f"{A}/{B}"
            # 等级 make_it_as_number_as_possible
            acc_info_dict["dengji"] = self.ocr_int(29,
                                                   43,
                                                   60,
                                                   67,
                                                   screen_shot=screen_shot)
            # mana
            if use_pcrocr_to_process_basic_text:
                acc_info_dict["mana"] = make_it_as_number_as_possible(
                    self.ocr_center(107, 54, 177, 76, screen_shot=screen_shot, custom_ocr="pcr", allowstr="0123456789,") \
                        .replace(',', ''))
            else:
                acc_info_dict["mana"] = make_it_as_number_as_possible(
                    self.ocr_center(107, 54, 177, 76, screen_shot=screen_shot, size=2.0) \
                        .replace(',', '').replace('.', ''))
            # 宝石
            if use_pcrocr_to_process_basic_text:
                acc_info_dict["baoshi"] = make_it_as_number_as_possible(
                    self.ocr_center(258, 52, 306, 72, screen_shot=screen_shot, custom_ocr="pcr", allowstr="0123456789,") \
                        .replace(',', ''))
            else:
                acc_info_dict["baoshi"] = make_it_as_number_as_possible(
                    self.ocr_center(258, 52, 306, 72, screen_shot=screen_shot, size=2.0) \
                        .replace(',', '').replace('.', ''))
        if introduction_info:
            self.lock_img(ZHUCAIDAN_BTN["bangzhu"],
                          elseclick=[(871, 513)])  # 锁定帮助
            # 去简介
            self.lock_no_img(ZHUCAIDAN_BTN["jianjie"], elseclick=[(382, 230)])
            self.lock_img(ZHUCAIDAN_BTN["jianjie_L"],
                          elseclick=[(382, 230)])  # 锁定简介
            screen_shot = self.getscreen()
            acc_info_dict["jianjie_name"] = self.ocr_center(
                608, 151, 879, 178, screen_shot=screen_shot, size=2.0)
            acc_info_dict["dengji"] = self.ocr_int(702,
                                                   184,
                                                   785,
                                                   205,
                                                   screen_shot=screen_shot)
            acc_info_dict["jianjie_zhanli"] = self.ocr_int(
                702, 214, 786, 235, screen_shot=screen_shot)
            acc_info_dict["jianjie_hanghui"] = self.ocr_center(
                703, 243, 918, 266, screen_shot=screen_shot, size=2.0)
            acc_info_dict["jianjie_id"] = str(
                self.ocr_int(598, 415, 768, 435, screen_shot=screen_shot))
        if props_info:
            self.lock_img(ZHUCAIDAN_BTN["bangzhu"],
                          elseclick=[(871, 513)])  # 锁定帮助
            # 去道具
            self.lock_no_img(ZHUCAIDAN_BTN["daoju"], elseclick=[(536, 159)])
            self.lock_img(ZHUCAIDAN_BTN["daojuyilan"],
                          elseclick=[(536, 159)])  # 锁定道具一览
            screen_shot = self.getscreen()
            self.click_img(screen=screen_shot,
                           img="img/zhucaidan/saodangquan.bmp")
            time.sleep(2)
            screen_shot = self.getscreen()
            acc_info_dict["saodangquan"] = self.get_daoju_number(
                screen_shot, must_int=False)
        if char_info:
            self.lock_home()
            self.click_btn(MAIN_BTN["juese"], until_appear=JUESE_BTN["duiwu"])
            at1 = (38, 79, 314, 206)
            at2 = (334, 79, 610, 206)
            at3 = (628, 79, 911, 206)
            at4 = (38, 228, 314, 350)
            at5 = (334, 228, 610, 350)
            at6 = (633, 228, 911, 350)
            at_list = [at1, at2, at3, at4, at5, at6]
            charlist = []
            P = pathlib.Path("img/juese/plate/")
            cm = CharMenu(self)
            cm.sort_by(cat="star")
            while True:
                sc = self.getscreen()
                for p in P.iterdir():
                    p = str(p).replace('\\', '/')
                    if p[-4:] == ".bmp":
                        for area in at_list:
                            if self.is_exists(img=p, at=area, screen=sc):
                                name = get_name_from_plate_path(p)
                                charlist.append(name)

                if cm.check_buttom() is True:
                    break
                else:
                    cm.dragdown()
                    if self.is_exists(JUESE_BTN["weijiesuo_w"],
                                      at=(21, 144, 167, 463)):
                        break
                    continue

            out = ','.join(charlist)
            acc_info_dict["charlist"] = out
        acc_info_list.append(acc_info_dict)
        self.lock_home()
        # 表格数据整理和转换
        if out_xls:
            # 将字典列表转换为DataFrame
            pf = pd.DataFrame(list(acc_info_list))
            # 指定字段顺序
            order = [
                'dengji', 'jianjie_name', 'tili', 'mana', 'baoshi',
                'jianjie_zhanli', 'jianjie_hanghui', 'jianjie_id', 'zhanghao',
                'group', 'charlist', 'saodangquan', 'date'
            ]
            pf = pf[order]
            # 将列名替换为中文
            columns_map = {
                'dengji': '等级',
                'jianjie_name': '名字',
                'tili': '体力',
                'mana': '玛娜数量',
                'baoshi': '宝石数量',
                'jianjie_zhanli': '全角色战力',
                'jianjie_hanghui': '所属行会',
                'jianjie_id': '玩家ID',
                'zhanghao': '账号',
                'group': '所在组',
                'charlist': '持有角色',
                'saodangquan': '所拥有的扫荡券',
                'date': '录入日期',
            }
            pf.rename(columns=columns_map, inplace=True)

            if acc_nature == 0:
                # 小号/农场号输出格式
                xls_path = 'xls/%s-pcr_farm_info.xlsx' % self.today_date
            elif acc_nature == 1:
                # 大号统一文件格式
                xls_path = 'xls/pcr_farm_info.xlsx'
            else:
                # 乱输入就这样的格式
                xls_path = 'xls/%s-pcr_farm_info.xlsx' % self.today_date

            # 将空的单元格替换为空字符
            pf.fillna('', inplace=True)
            # 判断文件是否存在
            if not os.path.exists(xls_path):
                # 输出
                # 指定生成的Excel表格名称
                file_path = pd.ExcelWriter(xls_path, engine='openpyxl')
                pf.to_excel(file_path,
                            engine='openpyxl',
                            encoding='utf-8',
                            index=False)
                # 保存表格
                file_path.save()
                return acc_info_dict
            # 多进程怎么加锁QAQ

            # 保存表格
            index = len(list(acc_info_list))  # 获取需要写入数据的行数
            workbook = openpyxl.load_workbook(xls_path)  # 打开表格
            sheets = workbook.sheetnames  # 获取表格中的所有表格
            worksheet = workbook[sheets[0]]  # 获取表格中所有表格中的的第一个表格
            rows_old = worksheet.max_row  # 获取表格中已存在的数据的行数
            for i in range(0, index):
                for j in range(0, len(list(acc_info_list)[i])):
                    # 追加写入数据,注意是从i+rows_old行开始写入
                    worksheet.cell(row=i + 1 + rows_old, column=1 +
                                   j).value = list(acc_info_dict.values())[j]
            workbook.save(xls_path)  # 保存表格

        return acc_info_dict