annotate getlist.py @ 30:6f784c5d13ce

add getlist.py
author Paper <mrpapersonic@gmail.com>
date Mon, 31 May 2021 15:37:50 -0400
parents
children b5cf08125fd5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 import urllib.request, json, re, sys
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 id = input("What is the MyAnimeList ID for your anime?: ")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 try:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 temp = int(id)
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 except:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 print("Not a valid MyAnimeList ID! Exiting.")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 sys.exit()
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 data = json.loads(url.read().decode())
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 count = 0
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 for i in range(len(data["episodes"])):
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 if count == 0:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 f = open("list.txt", "w", encoding="utf-8")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 else:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 f = open("list.txt", "a", encoding="utf-8")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 """
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 this is really hard to read at first glance so i'll break it down
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 it replaces "?" and ":" with legal counterparts so windows stops screaming
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 then strips among a dash (which usually shows different parts in an episode)
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 it then removes the last part of the string cause most, if not of MAL's have spaces before slashes
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 """
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 count += 1
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 f.close()