From b652d205915c805f3a5bb22307bc07482e63dd55 Mon Sep 17 00:00:00 2001 From: marios8543 Date: Sat, 25 Apr 2020 21:31:29 +0300 Subject: [PATCH] Upload files to 'anime_scripts' --- anime_scripts/seasons.py | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/anime_scripts/seasons.py b/anime_scripts/seasons.py index 014c39c..d53fe0d 100644 --- a/anime_scripts/seasons.py +++ b/anime_scripts/seasons.py @@ -75,8 +75,6 @@ def get_show(id): return response.json() raise ValueError("Bad show") -items = [] - def get_base_show(res): base = res["data"]["Media"] return SortableAnime(base["id"], base["startDate"]["year"], "BASE", base["title"], base["format"]) @@ -89,27 +87,31 @@ def process_shows(res): pass return ls -show_id = search(argv[1]) -res = get_show(show_id) -items.extend(process_shows(res)) -base_show = get_base_show(res) +def main(query): + items = [] + show_id = search(query) + res = get_show(show_id) + items.extend(process_shows(res)) + base_show = get_base_show(res) -if "PREQUEL" not in [i.type for i in items]: - season = 1 -else: - ignore = [] - while True: - f = False - for i in items: - if i.type == "PREQUEL" and i not in ignore: - fi = [i for i in process_shows(get_show(i.id)) if i not in items] - items.extend(fi) - ignore.append(i) - f = True - if not f: - break - items = [i for i in items if i.frmt == "TV"] - items.sort(key=lambda i: i.year) - season = items.index(base_show)+1 + if "PREQUEL" not in [i.type for i in items]: + season = 1 + else: + ignore = [] + while True: + f = False + for i in items: + if i.type == "PREQUEL" and i not in ignore: + fi = [i for i in process_shows(get_show(i.id)) if i not in items] + items.extend(fi) + ignore.append(i) + f = True + if not f: + break + items = [i for i in items if i.frmt == "TV"] + items.sort(key=lambda i: i.year) + season = items.index(base_show)+1 + return season -print("Season {}".format(season)) +if __name__ == "__main__": + print("Season {}".format(main(argv[1])))