Commit fbdbe296ec

fbdbe296ec57e976c84aee18620186e72ad1833e

parent: f9068c9ca4

Unsigned

Wraient <wraient.911@gmail.com> · 2024-09-22 03:00 UTC

generate and save token added

Layout: unified · split

curd.py +22 −5
@@ -173,7 +173,6 @@ if not os.path.exists("./scripts/tmp/"):
173173 except:
174174 pass
175175
176access_token = os.environ.get('ANILIST_ACCESS_TOKEN')
177176rewatching = False
178177
179178parser = argparse.ArgumentParser(description="Print a greeting message.")
@@ -183,6 +182,28 @@ parser.add_argument("-sub", action='store_true', help="Anime audio type (optiona
183182parser.add_argument("-dub", action='store_true', help="Anime audio type (optional)")
184183args = parser.parse_args()
185184
185user_config = load_config() # python dictionary containing all the configs as key value pairs
186history_file_path_ = os.path.expandvars(get_userconfig_value(user_config, "history_file"))
187history_file_path_ = os.path.dirname(history_file_path_)
188access_token_path = os.path.join(history_file_path_, "token")
189
190if os.path.exists(access_token_path):
191 # Read and use the token
192 with open(access_token_path, "r") as token_file:
193 access_token = token_file.read().strip()
194 print(f"Token found: {access_token}")
195
196else:
197 print("Generate the token from https://anilist.co/api/v2/oauth/authorize?client_id=20686&response_type=token ")
198 access_token = input("Token file not found. Please generate and enter your token: ")
199 with open(access_token_path, "w") as token_file:
200 token_file.write(access_token)
201 print(f"Token saved to {access_token_path}")
202
203if access_token == None:
204 print("No Access_token provided.")
205 exit(1)
206
186207if args.new:
187208 new_anime_name_ = input("Enter anime name: ")
188209 temp__ = search_anime_anilist(new_anime_name_, access_token)
@@ -194,11 +215,7 @@ if args.new:
194215
195216user_id, user_name = get_anilist_user_id(access_token)
196217
197if access_token == None:
198 print("No Access_token provided.")
199 exit(1)
200218
201user_config = load_config() # python dictionary containing all the configs as key value pairs
202219anilist_user_data = download_anilist_data(access_token, user_id)
203220anime_dict = extract_anime_info(anilist_user_data)[0]
204221select_anime(anime_dict)