Commit 10832a6d38

10832a6d38e13b21ca532921b7df15b8d9a4bf7c

parent: 011e88ec66

Unsigned

Wraient <wraient.911@gmail.com> · 2024-08-25 11:48 UTC

used other scripts

Layout: unified · split

curd.py +72 −24
@@ -7,35 +7,71 @@ import re
7import os 7import os
8import json 8import json
9from anilist import search_anime_by_title 9from anilist import search_anime_by_title
10from anilist import get_user_data
11from select_link import load_links
12from start_video import *
13from select_anime import load_anime_data
14from select_anime import extract_anime_info
15from select_anime import select_anime
16
17access_token = os.environ.get('ANILIST_ACCESS_TOKEN')
18user_id = os.environ.get('ANILIST_USER_ID')
19
20# print(access_token)
21# print(user_id)
22
23def run_script(script):
24 os.system(f"./scripts/{script}.sh")
25
26print("downloading user data")
27anilist_user_data = get_user_data(access_token, user_id)
28try:
29 if anilist_user_data['data'] == None:
30 print("Cannot process user data.")
31 print(anilist_user_data)
32 exit()
33except:
34 pass
10 35
11with open("scripts/tmp/query", "w") as file: 36with open("scripts/tmp/query", "w") as file:
12 file.write(input("Enter the anime you want:\n")) 37 file.write(input("Enter the anime you want:\n"))
13 38
14os.system("./scripts/anime_list.sh") 39# os.system("./scripts/anime_list.sh"
15 40
16import select_anime 41run_script("anime_list")
17
18with open("scripts/tmp/anime", "r") as anime:
19 anime_name = anime.read()
20 42
21with open('response.json', 'r') as file: 43with open('response.json', 'r') as file:
22 data = json.load(file) 44 data = json.load(file)
23 45
46# print(data)
47# print(type(data['data']))
48
49# anime_dict = extract_anime_info(anilist_user_data)[0]
50# print(anime_dict)
51anime_dict = load_anime_data("scripts/tmp/anime_list")
52print(anime_dict)
53# print(f"ANIME DICT = {anime_dict}")
54select_anime(anime_dict)
55
56with open("scripts/tmp/anime", "r") as anime:
57 anime_name = anime.read()
58
24# Remove everything from the last '(' including the parentheses 59# Remove everything from the last '(' including the parentheses
25cleaned_text = re.sub(r'\(.*$', '', anime_name).strip() 60cleaned_text = re.sub(r'\(.*$', '', anime_name).strip()
26 61
27# try: 62try:
28result = search_anime_by_title(data, cleaned_text)[0] 63 result = search_anime_by_title(anilist_user_data, cleaned_text)[0]
29print(result) 64 print(result)
30anime_id = result['id'] 65 anime_id = result['id']
31progress = int(result['progress']) 66 progress = int(result['progress'])
32title = result['english_title'] 67 title = result['english_title']
33# except: 68except:
34 # print("fucked up") 69 print("fucked up")
35 # anime_id = 98460 70 anime_id = 98460
71 progress = 0
36 72
37 73# os.system("./scripts/episode_list.sh")
38os.system("./scripts/episode_list.sh") 74run_script("episode_list")
39 75
40# with open("scripts/tmp/episode_list") as ep_list: 76# with open("scripts/tmp/episode_list") as ep_list:
41# temp = ep_list.read() 77# temp = ep_list.read()
@@ -43,18 +79,25 @@ os.system("./scripts/episode_list.sh")
43# last_episode = temp[-1] 79# last_episode = temp[-1]
44# ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n") 80# ep_no = input(f"Enter episode number: (number of episodes: {last_episode})\n")
45 81
46os.system("./scripts/episode_url.sh")
47
48
49# Define the title to search for
50# search_title = '' # Replace with the actual title you're searching for
51
52with open("scripts/tmp/ep_no", "w") as ep_no_file: 82with open("scripts/tmp/ep_no", "w") as ep_no_file:
53 # ep_no.write("1") 83 # ep_no.write("1")
54 # ep_no_file.write(ep_no) 84 # ep_no_file.write(ep_no)
55 ep_no_file.write(str(progress)) 85 with open("scripts/tmp/episode_list") as ep_list:
86 temp = ep_list.read()
87 temp = temp.split()
88 last_episode = int(temp[-1])
89
90 if progress == last_episode:
91 user_input = input("Do you want to start this anime from beginning?")
92 if user_input.lower() == "yes" or user_input.lower() == "y" or user_input.lower() == "":
93 progress = 0
94 else:
95 progress = last_episode - 1
96
97 print(progress)
98 ep_no_file.write(str(progress+1))
56 99
57# Search for the anime and get its ID 100os.system("./scripts/episode_url.sh")
58 101
59# Print the result 102# Print the result
60if anime_id: 103if anime_id:
@@ -62,4 +105,9 @@ if anime_id:
62else: 105else:
63 print("Anime not found.") 106 print("Anime not found.")
64 107
108# with open("scripts/tmp/link", 'r') as links:
109# link = links.read()
110
111links = load_links("scripts/tmp/links")
65 112
113start_video(links[0][1])