Commit 88755d6f19

88755d6f1915c497fba50c20e9da18146a6b8309

parent: 3a45c73812

Unsigned

Wraient <wraient.911@gmail.com> · 2024-10-06 06:23 UTC

auto find access token

Layout: unified · split

curd.py +12
@@ -20,6 +20,7 @@ import requests
20import csv 20import csv
21import math 21import math
22import socket 22import socket
23import urllib.parse
23# pypresence is also imported later if user enabled it in the config 24# pypresence is also imported later if user enabled it in the config
24 25
25discord_client_id = "1287457464148820089" 26discord_client_id = "1287457464148820089"
@@ -1115,6 +1116,17 @@ if os.path.exists(access_token_path):
1115else: 1116else:
1116 print("Generate the token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token ") 1117 print("Generate the token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token ")
1117 access_token = input("Token file not found. Please generate and enter your token: ") 1118 access_token = input("Token file not found. Please generate and enter your token: ")
1119 if "https://" in access_token:
1120 # Parse the URL fragment part (after the `#`)
1121 fragment = urllib.parse.urlparse(access_token).fragment
1122
1123 # Parse the fragment into components
1124 params = urllib.parse.parse_qs(fragment)
1125
1126 # Extract only the access_token without any other parameters
1127 access_token = params['access_token'][0] if 'access_token' in params else None
1128
1129 print("Access Token:", access_token)
1118 with open(access_token_path, "w") as token_file: 1130 with open(access_token_path, "w") as token_file:
1119 token_file.write(access_token) 1131 token_file.write(access_token)
1120 print(f"Token saved to {access_token_path}") 1132 print(f"Token saved to {access_token_path}")