Advertisement
Guest User

anime

a guest
Jun 25th, 2019
3,968
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. #!/bin/python
  2.  
  3. from jikanpy import Jikan
  4. from termcolor import colored
  5. import sys
  6. import inquirer
  7. import re
  8.  
  9.  
  10. jikan = Jikan()
  11.  
  12. def anime_name(anime):
  13.     anime = str(anime)
  14.     search = jikan.search('anime', anime)
  15.     return search
  16.  
  17.  
  18. def anime_download(items, anime):
  19.     items_crop = items['results'][:10]
  20.     my_anime_list = []
  21.     for each in items_crop:
  22.         if each.get('type') == 'OVA' or each.get('type') == 'Special' or each.get('type') == 'Movie':
  23.             continue
  24.         else:
  25.             my_anime_list.append(each['title'])
  26.        
  27.     my_anime_list = [anime_name.lower() for anime_name in my_anime_list]
  28.  
  29.        
  30.     final_list = []
  31.     for item in my_anime_list:
  32.         item = item.title()
  33.         final_list.append(item)
  34.        
  35.        
  36.    
  37.     print(final_list)
  38.     list_length = len(final_list)
  39.  
  40.     if list_length == 0:
  41.         print("Not found")
  42.  
  43.     elif list_length > 1:
  44.         which_anime = [
  45.             inquirer.List('Anime',
  46.                           message="Which one you need to download? ",
  47.                           choices=final_list,
  48.                           ), ]
  49.  
  50.         answer = inquirer.prompt(which_anime)
  51.         chosen_anime = answer['Anime']
  52.  
  53.  
  54.     elif list_length == 1:
  55.         chosen_anime = final_list[0]
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. def anime_show(items):
  63.     items_crop = items['results'][:10]
  64.  
  65.     for each in items_crop:
  66.         if each.get('type') == 'OVA' or each.get('type') == 'Special':
  67.             continue
  68.         else:
  69.             print(colored('Name:', 'green'), each['title'])
  70.  
  71.             if each.get('type') == 'TV':
  72.                 print(colored('Start Date:', 'green'), colored(each['start_date'][:4], 'red'))
  73.  
  74.                 if each.get('end_date') == None:
  75.                     print(colored('End Date:', 'green'), colored('Not finished', 'red'))
  76.  
  77.                 else:
  78.                     print(colored('End Date:', 'green'), colored(each['end_date'][:4], 'red'))
  79.  
  80.                 test = each['episodes']
  81.                 if test == 0:
  82.                     pass
  83.                 else:
  84.                     print(colored('Episodes:', 'green'), colored(each['episodes'], 'red'))
  85.  
  86.  
  87.             elif each.get('type') == 'Movie':
  88.                 print(colored('Released on:', 'green'), colored(each['start_date'][:4], 'red'))
  89.  
  90.  
  91.             print(colored('Score:', 'green'), colored(each['score'], 'red'))
  92.             print(colored('MAL link:', 'green'), colored(each['url'], 'blue'))
  93.             print('')
  94.             print(colored('Description: ', 'green'), each['synopsis'])
  95.             print('')
  96.             print('-' * 80)
  97.  
  98.  
  99. try:
  100.     if sys.argv[1] == "--search":
  101.         try:
  102.             anime = sys.argv[2]
  103.             items = anime_name(anime)
  104.             anime_show(items)
  105.         except IndexError:
  106.             print('ERR: No Anime Name Is Given To Search!')
  107.  
  108.     elif sys.argv[1] == "--download":
  109.         try:
  110.             anime = sys.argv[2]
  111.             items = anime_name(anime)
  112.             anime_download(items, anime)
  113.         except IndexError:
  114.             print('ERR: No Anime Name Is Given To Download!')
  115.            
  116.  
  117. except IndexError:
  118.     print('Enter an option.\nOptions can be:\n  --search\n  --season\n  --download\n  --random')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement