def _get_creds( self, credentials="credentials.json", token="gdrive.token", scopes=['https://www.googleapis.com/auth/drive'], headless=False, ): if Path(credentials).is_file(): with open(credentials, "r") as credentials_stream: cred_json = json_reader(credentials_stream) creds = None if Path(token).is_file(): with open(token, "r") as token_stream: creds = self._json_to_cred( token_stream, cred_json["installed"]["client_id"], cred_json["installed"]["client_secret"]) if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( credentials, scopes, ) if headless: creds = flow.run_console() else: creds = flow.run_local_server(port=0) with open(token, "w") as token_stream: json_writer( self._cred_to_json(creds), token_stream, indent=2, ) return creds
def write_index_to_file( self, index_path ): """Writes the instance index to index file""" Path(index_path).parent.resolve().mkdir(parents=True, exist_ok=True) with open(index_path, "w") as index_fp: json_writer(self.index, index_fp, indent=2)