annotate getlist.py @ 31:b5cf08125fd5

add deleteautosave.py
author Paper <mrpapersonic@gmail.com>
date Sat, 05 Jun 2021 16:32:38 -0400
parents 6f784c5d13ce
children fdbafd3e86d9
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
31
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
3 id = sys.argv[1]
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
4 if not 'id' in locals() or not 'id' in globals():
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
5 id = input("What is the MyAnimeList ID for your anime?: ")
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 try:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 temp = int(id)
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 except:
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 print("Not a valid MyAnimeList ID! Exiting.")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 sys.exit()
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 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
13 data = json.loads(url.read().decode())
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 count = 0
31
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
15 f = open("list.txt", "w", encoding="utf-8")
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
16 f.write("")
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
17 f.close()
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 for i in range(len(data["episodes"])):
31
b5cf08125fd5 add deleteautosave.py
Paper <mrpapersonic@gmail.com>
parents: 30
diff changeset
19 f = open("list.txt", "a", encoding="utf-8")
30
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 """
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 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
22 it replaces "?" and ":" with legal counterparts so windows stops screaming
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 then strips among a dash (which usually shows different parts in an episode)
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 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
25 """
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n")
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 count += 1
6f784c5d13ce add getlist.py
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 f.close()