Mercurial > codedump
diff getlist.py @ 40:2aa9614cb39a
flake8
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 21 Jun 2021 15:16:15 -0400 |
parents | fdbafd3e86d9 |
children | 37f231f85a67 |
line wrap: on
line diff
--- a/getlist.py Mon Jun 21 13:58:31 2021 -0400 +++ b/getlist.py Mon Jun 21 15:16:15 2021 -0400 @@ -1,32 +1,39 @@ -import urllib.request, json, re, sys +import urllib.request +import json +import sys # Initialize variables -key = "f090bb54758cabf231fb605d3e3e0468" # https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36 +# https://github.com/xbmc/metadata.themoviedb.org.python/blob/master/python/lib/tmdbscraper/tmdbapi.py#L36 +key = "f090bb54758cabf231fb605d3e3e0468" # Ask for source -if not 2 >= len(sys.argv): source = sys.argv[1] -if not 'source' in locals() or not 'source' in globals(): - source = input("Which website would you like to pull titles from? [tmdb, mal]: ") +if not 2 >= len(sys.argv): + source = sys.argv[1] +if 'source' not in locals() or 'source' not in globals(): + source = input( + "Which website would you like to pull titles from? [tmdb, mal]: ") while source not in ["tmdb", "mal"]: print("Not a valid source! Exiting.") sys.exit() # Ask for ID -if not 3 >= len(sys.argv): source = sys.argv[2] -if not 'id' in locals() or not 'id' in globals(): +if not 3 >= len(sys.argv): + source = sys.argv[2] +if 'id' not in locals() or 'id' not in globals(): id = input("What is the ID for your show?: ") try: temp = int(id) -except: +except Exception: print("Not a valid ID! Exiting.") sys.exit() # Scrapers if source == 'tmdb': - season = input("Which season do you want?: ") # required because api is... odd + # required because api is... odd + season = input("Which season do you want?: ") try: temp = int(season) - except: + except Exception: print("Not a valid season! Exiting.") sys.exit() data = json.loads(urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}?api_key={key}').read().decode()) @@ -35,11 +42,13 @@ f.write("") f.close() count = 1 - for i in range(amount): # this may count as spamming the api but i don't care lol - with urllib.request.urlopen(f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: + for i in range(amount): # this may count as spamming the api but i don't care lol + with urllib.request.urlopen( + f'https://api.themoviedb.org/3/tv/{str(id)}/season/{season}/episode/{count}?api_key={key}') as url: data = json.loads(url.read().decode()) f = open("list.txt", "a", encoding="utf-8") - f.write(data["name"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") + f.write(data["name"].replace("?", "?").replace( + ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") count += 1 f.close() if source == 'mal': @@ -51,6 +60,7 @@ f.close() for i in range(len(data["episodes"])): f = open("list.txt", "a", encoding="utf-8") - f.write(data["episodes"][count]["title"].replace("?", "?").replace(":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") + f.write(data["episodes"][count]["title"].replace("?", "?").replace( + ":", "꞉").replace('"', "“").split("/")[0].rstrip() + "\n") count += 1 f.close()