def initialize_esi_client(refresh_token=None): """ Retrieves a public or authorized ESI client. Args: auth_id (optional): refresh_token of the user whose client we want to retrieve. By default, a public ESI client is returned. Returns: esi_client (EsiClient): Client object from esipy. """ auth = EsiSecurity( headers={'User-Agent': client_name}, redirect_uri='https://localhost/callback', client_id=client_id, secret_key=secret_key, ) if refresh_token is not None: auth.refresh_token = refresh_token esi_client = EsiClient( auth, retry_requests=True, cache=DictCache(), headers={'User-Agent': client_name}, ) return esi_client
def ESIMail(self, KilledCharID): security = EsiSecurity( app=self.app, redirect_uri='http://localhost/callback/', client_id=GlobalConsts.CLIENTID, secret_key=GlobalConsts.SECRETKEY, ) print(security.get_auth_uri(scopes=GlobalConsts.REQUESTSCOPES)) try: tokens = security.auth(GlobalConsts.CHARAUTHTOKEN) except: security.refresh_token = GlobalConsts.CHARREFRESHTOKEN tokens = security.refresh() accessToken = tokens[GlobalConsts.TOKENAUTHKEY] RefreshToken = tokens[GlobalConsts.TOKENREFRESHKEY] expire_date = datetime.fromtimestamp( time.time() + tokens[GlobalConsts.TOKENEXPIRESKEY], ) api_info = security.verify() strCharacterID = api_info['CharacterID'] Response = SendMail(strCharacterID, KilledCharID, GlobalConsts.DEFAULTMESSAGE, accessToken) if Response.status_code == GlobalConsts.SUCCESSRESPONSECODE: print("Sent message to characterid {0}".format(KilledCharID)) else: print("Failed to send message to characterid {0}".format( KilledCharID))