Jupter-Lab Startegy creator Scrap data Explore database

Without DynDNS

Or how to easely accces remotely to a personnal workstation ?



Accessing remotely to a personnal workstation form outside of the local network, could be painfull. required some (not always simple) configuration, and maintenance...

Telegram and some python package let a simple configuration with very few steps.
pyTelegramBotAPI is a pretty friendly python package to do this !

It's also possible to create a 'pseudo application' directly accessible from a Smart Phone, it's also 'Phone OS' independant :


'pyTelegramBotAPI server' forward message (and execute action if needed) between local network and smart phone (internet / external network).
A cafeinate like program should be use to launch the 'pyTelegramBotAPI server' in order to prevent the 'computer standby' state...

Below, an example of an "overload Asyncio client class" that listen and send messages via 'pyTelegramBotAPI server' through local network and internet :


   # see more here : https://github.com/toto1234567890/HireMe/tree/main

    asyncLock = None
    class ATelecommand:
        @aStickyTelecommand(delay=10, backoff=1, tries=-1) 
        @aStickyTelecommand(delay=DEFAULT_RETRY_PERIOD, backoff=1, tries=10, jitter=1)
        async def TeleCommand(self):
            global asyncLock
            asyncLock = self.get_asyncLook()
            self.state = 'started'
            async with await MyAsyncSocketObj(name=self.Name).make_connection(server=self.config.TB_IP, port=int(self.config.TB_PORT)) as TeleSocket:
                await self.logger.asyncInfo("{0} : Telecommand sending TCP address to TeleRemote.. .  . ".format(self.Name))
                AStarQsPort = int(TeleSocket.sock_info[1])
                await TeleSocket.send_data("{0}:{1}:{2}".format(self.Name, self.config.TB_IP, AStarQsPort))
                while self.state != POWER_OFF.starQs_message and self.state != CLOSE_ALL_POSITION_CONFIRMATION.starQs_message:
                    data = await TeleSocket.receive_data()
                    if not data:
                        await self.logger.asyncError("{0} : Telecommand, just lost connection with TeleRemote !".format(self.Name))
                        raise Exception("[Errno 61] Connection refused")
                    try:
                        if data != '0' and data != POWER_OFF.starQs_message and data != CLOSE_ALL_POSITION_CONFIRMATION.starQs_message: 
                            if isinstance(data, Qmsg):
                                self.TeleBufQ.append(data)
                                while len(self.TeleBufQ) > 0:
                                    data = self.TeleBufQ[-1]
                                    #self._send_priority_msg(data)
                                    self.TeleBufQ.popleft()
                            elif isinstance(data, SubsQ): 
                                # subscribe object... to send scripts directly from telecommand
                                pass
                            else:
                                # tele_funcs (telecommande functionnalities)
                                await TeleSocket.send_data(tele_funcs.Tele_Dispatcher(data, self.main_queue_beat))
                        else:
                            if data == POWER_OFF.starQs_message:
                                self.state = data
                                await self.killTele(TeleSocket=TeleSocket, poweroff_msg=POWER_OFF.starQs_response(self.Name), logger_msg="{0} : Telecommand, received 'power off' command, program killed at : {1} !!!".format(self.Name, datetime.utcnow()))
                            elif data == CLOSE_ALL_POSITION_CONFIRMATION.starQs_message:
                                self.state = data   
                                await self.stopTele(TeleSocket=TeleSocket)
                            else:
                                await TeleSocket.send_data(UNDER_CONSTRUCTION.starQs_response())
                    except Exception as e:
                        await self.logger.asyncCritical("{0} : Telecommand, critical error while trying to get message from TeleRemote : '{1}'".format(self.Name, e))
                        pass

        async def killTele(self, TeleSocket, poweroff_msg, logger_msg):
            linkedProc = psutilProcess(osGetppid())
            procChilds = linkedProc.children(recursive=True)
            if osName != 'nt':
                pidList = str(osGetppid())
                for procChild in procChilds:
                    pidList+=" "+str(procChild.pid)
            else:
                pidList = [int(osGetppid())]
                if not procChilds is None:
                    for procChild in procChilds:
                        pidList.append(procChild.pid)
            await asyncThreadQKill(pidList=pidList, logger=self.logger, logger_msg=logger_msg, TeleSocket=TeleSocket, poweroff_msg=poweroff_msg)

        async def _stop_tasks(self):
            global asyncLock
            async with asyncLock:
                for task in asyncioAll_tasks():
                    if task.get_name() in self.clients:
                        task.cancel()
        async def stopTele(self, TeleSocket):
            await self.asyncLoop.create_task(self._stop_tasks())
            await TeleSocket.send_data(CLOSE_ALL_POSITION_CONFIRMATION.starQs_response(self.Name))
            await self.logger.asyncInfo("AStarQs : '{0}' received 'stop' command, program stopped at : {1} !!!".format(self.Name, datetime.utcnow()))
            self.asyncLoop.stop()
            while True:
                if not self.asyncLoop.is_running():
                    break
                await asyncSleep(0.1)
            self.asyncLoop.close()