def setConfig(self): session_token = iksm.log_in(VERSION) iksm_session = iksm.get_cookie(session_token, LANG, VERSION) if FLAG_SALMON_STATS: webbrowser.open(URL) print(datetime.now().strftime("%H:%M:%S ") + "Login and Paste API token.") while True: # Waiting Input session_token & api-token try: token = input("") if len(token) == 64: # Simple Validation of api-token length try: int(token, 16) # Convert to Hex print(datetime.now().strftime("%H:%M:%S ") + "Valid token.") api_token = token break except ValueError: print(datetime.now().strftime("%H:%M:%S ") + "Paste API token again.") else: print(datetime.now().strftime("%H:%M:%S ") + "Paste API token again.") except KeyboardInterrupt: print("\nBye!") sys.exit(1) else: api_token = "none" self.param.setup(iksm_session, session_token, api_token)
def gen_new_cookie(reason): '''Attempts to generate new cookie in case provided one is invalid.''' if reason == "blank": print "Blank cookie. Trying to generate one given your session_token..." elif reason == "auth": # authentication error print "Bad cookie. Trying to generate a new one given your session_token..." else: # server error or player hasn't battled before print "Cannot access SplatNet 2 without having played at least one battle online." exit(1) if SESSION_TOKEN == "": print "session_token is blank. Please log in to your Nintendo Account to obtain your session_token." new_token = iksm.log_in() if new_token == None: print "There was a problem logging you in. Please try again later." else: config_data["session_token"] = new_token write_config(config_data) print "\nWrote session_token to config.txt." new_cookie = iksm.get_cookie( SESSION_TOKEN, USER_LANG) # error handling in get_cookie() config_data["cookie"] = new_cookie write_config(config_data) print "Wrote iksm_session cookie to config.txt.\nYour cookie: " + new_cookie
def login(self): Log("Log in, right click the \"Select this account\" button, copy the link address, and paste it below:" ) webbrowser.open(iksm.log_in()) while True: try: url_scheme = input("") session_token_code = re.search("de=(.*)&", url_scheme).group(1) self.session_token = iksm.get_session_token(session_token_code) self.iksm_session = iksm.get_cookie(self.session_token) Log("Success") break except KeyboardInterrupt: CLog("Keyboard Interrupt") sys.exit(1) except AttributeError: CLog("Invalid URL") except KeyError: CLog("Invalid URL") except ValueError as error: CLog(f"{error}") sys.exit(1) webbrowser.open(URL) Log("Login and Paste API token") while True: try: api_token = input("") if len(api_token) == 64: try: int(api_token, 16) self.api_token = api_token Log("Success") break except ValueError: Log("Paste API token again") else: Log("Paste API token again") except KeyboardInterrupt: Log("Bye Bye") sys.exit(1) except Exception as error: Log(f"{error}") sys.exit(1) self.output() # 設定ファイル書き込み
def gen_new_cookie(reason): '''Attempts to generate a new cookie in case the provided one is invalid.''' manual = False if reason == "blank": print("Blank cookie.") elif reason == "auth": # authentication error print("The stored cookie has expired.") else: # server error or player hasn't battled before print("Cannot access SplatNet 2 without having played at least one battle online.") sys.exit(1) if SESSION_TOKEN == "": print("session_token is blank. Please log in to your Nintendo Account to obtain your session_token.") new_token = iksm.log_in(A_VERSION) if new_token == None: print("There was a problem logging you in. Please try again later.") else: if new_token == "skip": # user has opted to manually enter cookie manual = True print("\nYou have opted against automatic cookie generation and must manually input your iksm_session cookie.\n") else: print("\nWrote session_token to config.txt.") config_data["session_token"] = new_token write_config(config_data) elif SESSION_TOKEN == "skip": manual = True print("\nYou have opted against automatic cookie generation and must manually input your iksm_session cookie. You may clear this setting by removing \"skip\" from the session_token field in config.txt.\n") if manual: new_cookie = iksm.enter_cookie() else: print("Attempting to generate new cookie...") acc_name, new_cookie = iksm.get_cookie(SESSION_TOKEN, USER_LANG, A_VERSION) config_data["cookie"] = new_cookie write_config(config_data) if manual: print("Wrote iksm_session cookie to config.txt.") else: print("Wrote iksm_session cookie for {} to config.txt.".format(acc_name))
def gen_new_cookie(reason): '''Attempts to generate new cookie in case provided one is invalid.''' manual = False if reason == "blank": print("Blank cookie.") elif reason == "auth": #authentication error print("The stored cookie has expired.") else: #server error or player hasn't battled before print("Cannnot access SplatNet 2 without having played at least one") exit(1) if SESSION_TOKEN == "": print("session_token is blank.Please log in to your Nintendo Account") new_token = iksm.log_in(A_VERSION) if new_token == None: print("There was a problem logging you in. Please try again later") else: if new_token == "skip": #user has opted to manually enter cookie manual = True print("\nYou have opted against automatic cookie generation\n") else: print("\nWrote session_token to config.txt.") config_data["session_token"] = new_token write_config(config_data) elif SESSION_TOKEN == "skip": manual = True print("\nYOu have opted against automatic") if manual: new_cookie = iksm.enter_cookie() else: new_cookie = iksm.get_cookie(SESSION_TOKEN, USER_LANG, A_VERSION) config_data["cookie"] = new_cookie write_config(config_data) print("Wrote iksm_session cookie to config.txt.")
async def register(self, ctx): '''Receive a Nintendo login link through DM's to link your Nintendo account to your Discord account. For help: https://youtu.be/4RD-3L7_vQI ''' await ctx.author.send(iksm.log_in(ctx))