#!/usr/bin/env python3 # mal-show - prints all completed anime/manga from bs4 import BeautifulSoup # for parsing xml import sys # for sys.argv and exit() from datetime import datetime # for getting current date from pathlib import Path # for path import tarfile # for extracting import os # for removing current_date = datetime.now().strftime('%d-%m-%Y') list_dir_path = Path.home() / 'Downloads' / 'anime-list' if len(sys.argv) <= 1 or (sys.argv[1] != 'anime' and sys.argv[1] != 'manga'): print('Please use anime or manga as sys.argv[1]') sys.exit() else: liststr = 'list-' + current_date + '.tar' try: listfile = tarfile.open(list_dir_path / liststr) except FileNotFoundError: print('List file not found, firstly run animelist-archive.py to download your list...') sys.exit() listfile.extractall() listfile.close() listfile = open(sys.argv[1] + '-' + current_date + '.xml') #print('Show unscored? ', end='') #b_show_unscored = pyip.inputYesNo() soup = BeautifulSoup(listfile, 'xml') if sys.argv[1] == 'anime': list_entries = soup.find_all('anime') else: list_entries = soup.find_all('manga') sorted_list_entries = sorted(list_entries, key=lambda anime: int(anime.find('my_score').text), reverse=True) for anime in sorted_list_entries: my_score = anime.find('my_score').text my_status = anime.find('my_status').text if my_status != 'Completed': continue if sys.argv[1] == 'anime': series_title = anime.find('series_title').text else: series_title = anime.find('manga_title').text if my_score == '0': # Show '-' instead of '0' my_score = '-' print(f"[{my_score}/10] {series_title}") os.remove('manga-' + current_date + '.xml') os.remove('anime-' + current_date + '.xml')