コード例 #1
0
 def create_device_id() -> str:
     """
     创建随机设备指纹
     """
     device_id = f"e{str(random.random())[2:17]}"
     debug(f"device_id: {device_id}")
     return device_id
コード例 #2
0
 def create_client_msg_id() -> str:
     """
     创建客户端信息指纹
     """
     client_msg_id = int(time.time() * 1e3) + random.randint(1, 1000)
     debug(f"client_msg_id: {client_msg_id}")
     return client_msg_id
コード例 #3
0
 def create_synckey(self):
     """
         组合生成synckey
     """
     synckey = "|".join([
         f"{item['Key']}_{item['Val']}"
         for item in self.__person_data["SyncKey"]["List"]
     ])
     debug(f"Synkey:[{synckey}]")
     return synckey
コード例 #4
0
 def get_timestamp(reverse: bool = False) -> int:
     """
     获取时间戳,支持取反
     """
     timestamp = None
     if not reverse:
         timestamp = int(time.time() * 1e3)
     else:
         timestamp = execjs.eval("~new Date")
     debug(f"timestamp: {timestamp}")
     return timestamp
コード例 #5
0
 def voice():
     debug("start voice detector")
     pygame.mixer.init()
     while True:
         if not self.__is_online:
             warning("voice detector offline")
             return
         while self.__voice_pool:
             pygame.mixer.music.load(self.__voice_pool.pop())
             pygame.mixer.music.play()
         time.sleep(2)
コード例 #6
0
    def run_add_on(self):

        debug("check add on")
        if conf.export_xlsx:
            Device.export_all_contact(self.__contacts, self.__session,
                                      self.__person_data)
        if conf.make_icon_wall:
            Device.make_icon_wall(
                API_media_icon_path,
                API_analysis_path / f"{self.__nick}_icon_wall.png",
                patterns="*_0",
            )
        if conf.sunburst_city:
            Device.export_sunburst_city(
                self.__contacts,
                API_analysis_path / f"{self.__nick}_sunburst_city.html")
コード例 #7
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
コード例 #8
0
 def interaction():
     """
         简单交互式面板
     """
     debug("start isnteraction")
     while True:
         if not self.__is_online or not conf.need_interaction:
             warning("isnteraction offline")
             return
         try:
             cmd = input(">>>")
             if not cmd:
                 pass
             else:
                 print(eval(cmd))
         except Exception as e:
             error(e)
         finally:
             time.sleep(0.1)
コード例 #9
0
 def worker():
     debug("start main loop")
     while True:
         try:
             sync_check_res = self.get_msg_signal()
             debug(f"sync_check_res: {sync_check_res}")
             retcode, selector = (
                 sync_check_res["retcode"],
                 sync_check_res["selector"],
             )
             if retcode == "0" and int(selector) > 0:
                 msgs = self.get_msg_contents()
                 debug(f"Contents: {msgs}")
                 for msg in msgs["AddMsgList"]:
                     _, result = self.data_ctrl(msg)
                     self.send_back(result)
             elif retcode == "1101":
                 self.__is_online = False
                 warning("main loop offline")
                 return
         except KeyboardInterrupt:
             return
         except Exception as e:
             error(e)
         finally:
             time.sleep(0.1)
コード例 #10
0
 def send_text(self, target, msg):
     """
         文本消息发送
     """
     jsondata = self.get_base_request()
     LocalID = str(execjs.eval("+new Date()"))
     jsondata.update({
         "Msg": {
             "Type": 1,
             "Content": msg,
             "FromUserName": self.__person_data["User"]["UserName"],
             "ToUserName": target,
             "LocalID": LocalID,
             "ClientMsgId": LocalID,
         },
         "Scene": 0,
     })
     fakeHeader = {
         "Accept": "application/json, text/plain, */*",
         "Accept-Encoding": "gzip, deflate, br",
         "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
         "Content-Type": "application/json;charset=UTF-8",
         "Host": "wx.qq.com",
         "Origin": "https://wx.qq.com",
         "Referer": "https://wx.qq.com/?&lang=zh_CN",
         "User-Agent": "Webot/1.0",
     }
     resp = self.post(
         API_webwxsendmsg,
         params={
             "lang": "zh_CN",
             "pass_ticket": self.__auth_data["pass_ticket"]
         },
         data=json.dumps(jsondata, ensure_ascii=False).encode("utf-8"),
         headers=fakeHeader,
     )
     warning(self.translate_text(f"🤖️->【{target}】: {msg}"))
     debug(resp.json())
コード例 #11
0
 def worker():
     debug("start main loop")
     while True:
         sync_check_res = self.get_msg_signal()
         debug(f"sync_check_res: {sync_check_res}")
         retcode, selector = (
             sync_check_res["retcode"],
             sync_check_res["selector"],
         )
         if retcode == "0" and int(selector) > 0:
             msgs = self.get_msg_contents()
             debug(f"Contents: {msgs}")
             for msg in msgs["AddMsgList"]:
                 _, result = self.data_ctrl(msg)
                 self.send_back(result)
         elif retcode == "1101":
             self.__is_online = False
             warning("main loop offline")
             return
コード例 #12
0
    def msg_worker(self):
        """
            消息处理
        """

        debug("start msg worker")

        def worker():
            debug("start main loop")
            while True:
                try:
                    sync_check_res = self.get_msg_signal()
                    debug(f"sync_check_res: {sync_check_res}")
                    retcode, selector = (
                        sync_check_res["retcode"],
                        sync_check_res["selector"],
                    )
                    if retcode == "0" and int(selector) > 0:
                        msgs = self.get_msg_contents()
                        debug(f"Contents: {msgs}")
                        for msg in msgs["AddMsgList"]:
                            _, result = self.data_ctrl(msg)
                            self.send_back(result)
                    elif retcode == "1101":
                        self.__is_online = False
                        warning("main loop offline")
                        return
                except KeyboardInterrupt:
                    return
                except Exception as e:
                    error(e)
                finally:
                    time.sleep(0.1)

        def interaction():
            """
                简单交互式面板
            """
            debug("start isnteraction")
            while True:
                if not self.__is_online or not conf.need_interaction:
                    warning("isnteraction offline")
                    return
                try:
                    cmd = input(">>>")
                    if not cmd:
                        pass
                    else:
                        print(eval(cmd))
                except Exception as e:
                    error(e)
                finally:
                    time.sleep(0.1)

        def voice():
            debug("start voice detector")
            pygame.mixer.init()
            while True:
                if not self.__is_online:
                    warning("voice detector offline")
                    return
                while self.__voice_pool:
                    pygame.mixer.music.load(self.__voice_pool.pop())
                    pygame.mixer.music.play()
                time.sleep(2)

        def trystart(item):
            try:
                item.start()
            except Exception as e:
                error(e)

        self.__thread_pool["msg_hook"] = threading.Thread(target=worker)
        self.__thread_pool["voice_hook"] = threading.Thread(target=voice)
        self.__thread_pool["interaction"] = threading.Thread(
            target=interaction)
        list(map(lambda item: trystart(item[1]), self.__thread_pool.items()))
        self.check_online_status()
コード例 #13
0
ファイル: common.py プロジェクト: vjingbi/Webot
def check_times(msg: str = "", level: int = 3):
    timeStart = time.time()
    yield
    debug(f"{msg} cost times: {round(time.time()-timeStart,level)}s")
コード例 #14
0
ファイル: core.py プロジェクト: keyman9848/Webot
 def run_add_on(self):
     debug("check add on")
     if conf.export_xlsx:
         Device.export_all_contact(self.__contacts, self.__session,
                                   self.__person_data)