示例#1
0
 def make_icon_wall(
     image_root_path: str,
     image_result_save_path: str = "./icon_wall.png",
     length: int = 1440,
     weight: int = 900,
     patterns: str = "*",
 ) -> pathlib.Path:
     """
     生成图片墙
     patterns: *_0 好友
           *   全部
     """
     images = list(
         filter(
             check_if_can_open,
             pathlib.Path(image_root_path).glob(f"**/{patterns}.png"),
         ))
     per_size = int(math.sqrt(length * weight / len(images)))
     image = Image.new("RGBA", (length, weight))
     for indexs, (x, y) in enumerate(
             product(range(int(length / per_size)),
                     range(int(weight / per_size)))):
         img = Image.open(images[indexs])
         img = img.resize((per_size, per_size), Image.ANTIALIAS)
         image.paste(img, (x * per_size, y * per_size))
     image.save(image_result_save_path)
     success(f"make icon wall: {image_result_save_path}")
     return pathlib.Path(image_result_save_path)
示例#2
0
 def login_success_init(self):
     """
         成功登陆并初始化wx
     """
     resp = self.post(
         API_webwxinit,
         params={
             "pass_ticket": self.__auth_data["pass_ticket"],
             "lang": "zh_CN"
         },
         json=self.get_base_request(),
     )
     resp.encoding = "utf8"
     self.__person_data = resp.json()
     self.__nick = self.__person_data["User"]["NickName"]
     conf.my_id = self.__person_data["User"]["UserName"]
     create_json(self.__person_data, API_static_path / "person_data.json")
     success(
         f"{'Welcome'.center(20,'*')}: [{self.__person_data['User']['NickName']}]"
     )
     save_worker(
         (
             self.__session,
             self.__auth_data,
             self.__person_data,
             self.__get_ticket_url,
         ),
         API_hotreload_file,
     )
示例#3
0
 def login_appwait(self, get_ticket=True):
     """
         等待本地终端确认
     """
     warning("Waiting for app confirm")
     resp = self.login_wait(False)
     if get_ticket:
         success("Login Success")
         self.__get_ticket_url = Parser.get_get_ticket_url(resp)
示例#4
0
 def export_sunburst_city(
         data: dict,
         image_result_save_path: str = "./sunburst_city.html"
 ) -> pathlib.Path:
     """
     导出城市分布图
     """
     image = (
         Sunburst(init_opts=opts.InitOpts(width="1000px",
                                          height="600px"))  # 设定画布长宽
         .add(
             "",
             data_pair=format_sunburst_city(data),  # 载入数据
             highlight_policy="ancestor",
             radius=[0, "95%"],
             sort_="null",
             levels=[
                 {},  # 第一圈样式,如果有国家的话就不会空着
                 {
                     "r0": "15%",
                     "r": "45%",
                     "itemStyle": {
                         "borderWidth": 2
                     },
                     "label": {
                         "rotate": "tangential"
                     },
                 },  # 第二圈样式,对标省
                 {
                     "r0": "35%",
                     "r": "70%",
                     "label": {
                         "position": "outside",
                         "padding": 3,
                         "silent": False
                     },
                     "itemStyle": {
                         "borderWidth": 1
                     },
                 },  # 最外圈样式,对标市
             ],
         )
         # 设定标题
         .set_global_opts(title_opts=opts.TitleOpts(
             title="Sunburst-城市分布")).set_series_opts(
                 label_opts=opts.LabelOpts(formatter="{b}"))  # 设定名称
     )
     path = image.render(image_result_save_path)
     success(f"make city sunburst: {path}")
     return pathlib.Path(path)
示例#5
0
 def check_online_status(self):
     """
         检查在线状态
     """
     try:
         while True:
             if not self.__is_online:
                 warning("ready for logout")
                 for name, threadTarget in self.__thread_pool.items():
                     debug(f"{name} closed!")
                     threadTarget.join()
                 success("end!")
                 exit()
             time.sleep(1)
     except Exception:
         self.__is_online = False
示例#6
0
    def export_all_contact(contacts: dict, session: requests.Session,
                           person_data: dict) -> pathlib.Path:
        """
        导出通讯录
        """
        warning("Contact exporting...")
        wb = Workbook()
        sheet = wb.active
        keys = contacts["MemberList"][0].keys()
        for x, key in enumerate(keys):
            sheet.cell(row=1, column=x + 1, value=key)
        for y, item in progressbar.progressbar(
                enumerate(contacts["MemberList"])):
            y = y + 2
            for x, key in enumerate(keys):
                x = x + 1
                data = item[key]

                if key != "HeadImgUrl":
                    if key == "MemberList":
                        data = "".join(data)
                    sheet.cell(row=y, column=x, value=data)
                else:
                    pic = get_pic(
                        session,
                        urljoin(API_target, data),
                        API_media_icon_path /
                        f"{item['PYInitial']}_{item['VerifyFlag']}.png",
                    )
                    if pic:
                        x = x - 1
                        index_code = string.ascii_uppercase[x]
                        size = (50, 50)
                        (
                            sheet.column_dimensions[index_code].width,
                            sheet.row_dimensions[y].height,
                        ) = size
                        img = openpyxlImage(BytesIO(pic))
                        img.width, img.height = size
                        sheet.add_image(img, f"{index_code}{y}")
                    else:
                        sheet.cell(row=y, column=x, value="")
        path = API_analysis_path / f'{person_data["User"]["NickName"]}_contacts.xlsx'
        wb.save(path)
        success(f"export contacts: {path}")
        return path
示例#7
0
文件: util.py 项目: keyman9848/Webot
    def export_all_contact(contacts, session, person_data):
        """
            导出通讯录
        """
        warning("Contact exporting...")
        wb = Workbook()
        sheet = wb.active
        keys = contacts["MemberList"][0].keys()
        for x, key in enumerate(keys):
            sheet.cell(row=1, column=x + 1, value=key)
        for y, item in progressbar.progressbar(
                enumerate(contacts["MemberList"])):
            y = y + 2
            for x, key in enumerate(keys):
                x = x + 1
                data = item[key]

                if key != "HeadImgUrl":
                    if key == "MemberList":
                        data = "".join(data)
                    sheet.cell(row=y, column=x, value=data)
                else:
                    picData = get_pic(session, data)
                    if picData:
                        x = x - 1
                        indexCode = string.ascii_uppercase[x]
                        size = (50, 50)
                        sheet.column_dimensions[
                            indexCode].width, sheet.row_dimensions[
                                y].height = size
                        img = openpyxlImage(BytesIO(picData))
                        img.width, img.height = size
                        sheet.add_image(img, f"{indexCode}{y}")
                    else:
                        sheet.cell(row=y, column=x, value="")
        wb.save(
            f'{API_conf_path}/{person_data["User"]["NickName"]}_contacts.xlsx')
        success("Complete!")
示例#8
0
 def get_qr_code_uuid(resp):
     code = re.split(r'"|";', resp.text)[1]
     success(f"GET QRCODE_UUID --> [{code}]")
     return code