Esempio n. 1
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)
Esempio n. 2
0
 def get_msg_signal(self):
     """
         消息信号检查
     """
     call_back = {"retcode": "0", "selector": "0"}
     try:
         resp = self.get(
             API_synccheck,
             params={
                 "r": Device.get_timestamp(),
                 "skey": self.__auth_data["skey"],
                 "sid": self.__auth_data["wxsid"],
                 "uin": self.__auth_data["wxuin"],
                 "deviceid": self.__device_id,
                 "synckey": self.create_synckey(),
                 "_": Device.get_timestamp(),
             },
             timeout=API_checktimeout,
         )
         if not resp.status_code == 200:
             raise AssertionError()
         call_back = execjs.eval(resp.text.replace("window.synccheck=", ""))
     except requests.exceptions.ReadTimeout:
         pass
     except requests.exceptions.Timeout:
         pass
     except Exception as e:
         error(e)
     time.sleep(1)
     return call_back
Esempio n. 3
0
 def wrapper(*args, **kwargs):
     func_name = func.__name__ if "__name__" in dir(func) else ""
     debug_error_log(f"start {func_name}")
     try:
         return func(*args, **kwargs)
     except KeyboardInterrupt:
         exit()
     except Exception as e:
         error(f"[{target} {func_name}]: {e}")
         if raise_exit:
             exit()
         elif raise_err:
             raise e
         return default
     finally:
         debug_error_log(f"end {func_name}", False)
Esempio n. 4
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)
Esempio n. 5
0
 def login(self):
     """
         获取认证数据
     """
     if self.__hot_reload and check_path(API_hotreload_file):
         try:
             self.__session, self.__auth_data, self.__person_data, self.__get_ticket_url = load_worker(
                 API_hotreload_file)
             # self.login_push_wait()
             # self.login_appwait(False)
         except Exception:
             error("Hot reload timeout!")
             self.__hot_reload = False
             self.login()
     else:
         self.get_qrcode_uid()
         self.get_qrcode_img()
         self.login_localwait()
         self.login_appwait()
Esempio n. 6
0
 def trystart(item):
     try:
         item.start()
     except Exception as e:
         error(e)