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/"):
173 except: 173 except:
174 pass 174 pass
175 175
176access_token = os.environ.get('ANILIST_ACCESS_TOKEN')
177rewatching = False 176rewatching = False
178 177
179parser = argparse.ArgumentParser(description="Print a greeting message.") 178parser = argparse.ArgumentParser(description="Print a greeting message.")
@@ -183,6 +182,28 @@ parser.add_argument("-sub", action='store_true', help="Anime audio type (optiona
183parser.add_argument("-dub", action='store_true', help="Anime audio type (optional)") 182parser.add_argument("-dub", action='store_true', help="Anime audio type (optional)")
184args = parser.parse_args() 183args = parser.parse_args()
185 184
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
186if args.new: 207if args.new:
187 new_anime_name_ = input("Enter anime name: ") 208 new_anime_name_ = input("Enter anime name: ")
188 temp__ = search_anime_anilist(new_anime_name_, access_token) 209 temp__ = search_anime_anilist(new_anime_name_, access_token)
@@ -194,11 +215,7 @@ if args.new:
194 215
195user_id, user_name = get_anilist_user_id(access_token) 216user_id, user_name = get_anilist_user_id(access_token)
196 217
197if access_token == None:
198 print("No Access_token provided.")
199 exit(1)
200 218
201user_config = load_config() # python dictionary containing all the configs as key value pairs
202anilist_user_data = download_anilist_data(access_token, user_id) 219anilist_user_data = download_anilist_data(access_token, user_id)
203anime_dict = extract_anime_info(anilist_user_data)[0] 220anime_dict = extract_anime_info(anilist_user_data)[0]
204select_anime(anime_dict) 221select_anime(anime_dict)