Mercurial > codedump
comparison getlist.py @ 40:2aa9614cb39a
flake8
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 21 Jun 2021 15:16:15 -0400 |
parents | fdbafd3e86d9 |
children | 37f231f85a67 |
comparison
equal
deleted
inserted
replaced
39:a93c352af05e | 40:2aa9614cb39a |
---|---|
1 import urllib.request, json, re, sys | 1 import urllib.request |
2 import json | |
3 import sys | |
2 | 4 |
3 # Initialize variables | 5 # Initialize variables |
4 key = "f090bb54758cabf231fb605d3e3e0468" # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36 | 6 # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36 |
7 key = "f090bb54758cabf231fb605d3e3e0468" | |
5 | 8 |
6 # Ask for source | 9 # Ask for source |
7 if not 2 >= len(sys.argv): source = sys.argv[1] | 10 if not 2 >= len(sys.argv): |
8 if not 'source' in locals() or not 'source' in globals(): | 11 source = sys.argv[1] |
9 source = input("Which website would you like to pull titles from? [tmdb, mal]: ") | 12 if 'source' not in locals() or 'source' not in globals(): |
13 source = input( | |
14 "Which website would you like to pull titles from? [tmdb, mal]: ") | |
10 while source not in ["tmdb", "mal"]: | 15 while source not in ["tmdb", "mal"]: |
11 print("Not a valid source! Exiting.") | 16 print("Not a valid source! Exiting.") |
12 sys.exit() | 17 sys.exit() |
13 | 18 |
14 # Ask for ID | 19 # Ask for ID |
15 if not 3 >= len(sys.argv): source = sys.argv[2] | 20 if not 3 >= len(sys.argv): |
16 if not 'id' in locals() or not 'id' in globals(): | 21 source = sys.argv[2] |
22 if 'id' not in locals() or 'id' not in globals(): | |
17 id = input("What is the ID for your show?: ") | 23 id = input("What is the ID for your show?: ") |
18 try: | 24 try: |
19 temp = int(id) | 25 temp = int(id) |
20 except: | 26 except Exception: |
21 print("Not a valid ID! Exiting.") | 27 print("Not a valid ID! Exiting.") |
22 sys.exit() | 28 sys.exit() |
23 | 29 |
24 # Scrapers | 30 # Scrapers |
25 if source == 'tmdb': | 31 if source == 'tmdb': |
26 season = input("Which season do you want?: ") # required because api is... odd | 32 # required because api is... odd |
33 season = input("Which season do you want?: ") | |
27 try: | 34 try: |
28 temp = int(season) | 35 temp = int(season) |
29 except: | 36 except Exception: |
30 print("Not a valid season! Exiting.") | 37 print("Not a valid season! Exiting.") |
31 sys.exit() | 38 sys.exit() |
32 data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode()) | 39 data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode()) |
33 amount = data["number_of_episodes"] | 40 amount = data["number_of_episodes"] |
34 f = open("list.txt", "w", encoding="utf-8") | 41 f = open("list.txt", "w", encoding="utf-8") |
35 f.write("") | 42 f.write("") |
36 f.close() | 43 f.close() |
37 count = 1 | 44 count = 1 |
38 for i in range(amount): # this may count as spamming the api but i don't care lol | 45 for i in range(amount): # this may count as spamming the api but i don't care lol |
39 with urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: | 46 with urllib.request.urlopen( |
47 f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: | |
40 data = json.loads(url.read().decode()) | 48 data = json.loads(url.read().decode()) |
41 f = open("list.txt", "a", encoding="utf-8") | 49 f = open("list.txt", "a", encoding="utf-8") |
42 f.write(data["name"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") | 50 f.write(data["name"].replace("?", "?").replace( |
51 ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") | |
43 count += 1 | 52 count += 1 |
44 f.close() | 53 f.close() |
45 if source == 'mal': | 54 if source == 'mal': |
46 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url: | 55 with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url: |
47 data = json.loads(url.read().decode()) | 56 data = json.loads(url.read().decode()) |
49 f = open("list.txt", "w", encoding="utf-8") | 58 f = open("list.txt", "w", encoding="utf-8") |
50 f.write("") | 59 f.write("") |
51 f.close() | 60 f.close() |
52 for i in range(len(data["episodes"])): | 61 for i in range(len(data["episodes"])): |
53 f = open("list.txt", "a", encoding="utf-8") | 62 f = open("list.txt", "a", encoding="utf-8") |
54 f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") | 63 f.write(data["episodes"][count]["title"].replace("?", "?").replace( |
64 ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") | |
55 count += 1 | 65 count += 1 |
56 f.close() | 66 f.close() |