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