Пример #1
0
    def __init__(self, address, file_path=None, file_name=None, nofile=False,
                 quiet=False, delay=0.22, timeout=3000, *args, **kwargs):
        """ Constructs a `Core` object.

        Instantiates a `ping` generator at `self.ping_generator`, and an
        open CSV writer at `self.cwriter`"""

        logger.debug((address, file_path, file_name, nofile, quiet, delay,
                      timeout, args, kwargs))

        self.quiet = not quiet  # flip bool
        self.delay = delay
        # core.Core.ping
        if address is None:
            raise RuntimeError('core.Core requires address')
        self.address = address
        self.ping_generator = ping(self.address, timeout=timeout,
                                   verbose=not self.quiet, delay=self.delay)

        # core.Core.build files
        self.file_path = file_path  # validated in self.build file
        self.file_name = file_name  # validated in self.build file
        self.nofile = nofile
        if not self.nofile:
            self.built_file = buildfile(self.file_path, self.file_name)
            logger.info('Log file at %s' % self.built_file.name)
            self.cwriter = csv.writer(self.built_file)
Пример #2
0
    def __init__(self, refresh_token: str = None):
        if not self.init:
            return
        self.init = False

        # build params
        self._ClientID = 'MOBrBDS8blbauoSck0ZfDbtuzpyT'
        self._ClientSecret = 'lsACyCD94FhDUtGTXi3QzcFE2uU1hqtDaKeqrdwj'
        self._LoginHash = '28c1fdd170a5204386cb1313c7077b34f83e4aaf4aa829ce78c231e05b0bae2c'

        # token
        self._AccessToken = None
        self._RefreshToken = refresh_token
        self._AccessTokenUpdateTime = 0

        # network
        self._DownloadThread = None

        # operating mechanism
        self._Refreshing = False
        self._SendTokenList = []

        self._load_setting()
        core_logger.info('Create TokenManager instance.')
Пример #3
0
 def _load_setting(self):
     # Pay attention to the real search path
     # Search path is running file path, not module path.
     if 'Token.json' in listdir('.'):
         with open('Token.json') as file:
             data = load(file)
             self._AccessToken = data['AccessToken']
             self._RefreshToken = data['RefreshToken']
             self._AccessTokenUpdateTime = data['AccessTokenUpdateTime']
         core_logger.info('Find token file, loading.')
         now_timestamp = int(datetime.now().timestamp())
         if now_timestamp - self._AccessTokenUpdateTime >= AccessTokenUpdateExpiration:
             self._AccessToken = None
             self._RefreshToken = None
             self._AccessTokenUpdateTime = 0
             core_logger.info('According to the last update date '
                              'more than 30 days, the data is cleared')
     else:
         core_logger.info('Not find token file.')
Пример #4
0
 def login(self, username: str, password: str) -> bool:
     core_logger.info('Login account.')
     return self.refresh_auth_token(username=username, password=password)