Source code for mal.commands

#!/usr/bin/env python
# coding=utf-8
#
#   Python Script
#
#   Copyright © Manoel Vilela
#
#

"""These function serve as an entry point for the several subcommands
of mal. All they do is basically call the functions that do actual work
in the core module."""

# stdlib
import sys

# self-package
from mal import core
from mal import login as _login
from mal import setup





[docs]def filter(mal, args): """Search and find an anime in the users list.""" core.find(mal, args.anime_regex.lower(), extra=args.extend, user=args.user)
[docs]def increase(mal, args): core.progress_update(mal, args.anime_regex.lower(), args.episodes)
[docs]def decrease(mal, args): core.progress_update(mal, args.anime_regex.lower(), -args.episodes)
[docs]def login(mal, args): """Creates login credentials so that next time the program is called it can log in right at the start without any problem.""" _login.create_credentials() sys.exit(0)
[docs]def list(mal, args): """Show all the animes on the users list.""" # . matches any character except line breaks # + matches one or more occurences of the previous character core.find(mal, '.+', args.section, extra=args.extend, user=args.user)
[docs]def drop(mal, args): """Drop a anime from lists based in a regex expression""" core.drop(mal, args.anime_regex)
[docs]def stats(mal, args): """Show the users anime watching statistics as presented on MAL.""" core.stats(mal, args.user)
[docs]def add(mal, args): """Add an anime with a certain status to the list.""" core.add(mal, args.anime_regex.lower(), status=args.status)
[docs]def config(mal, args): # Show the current config file setup.print_config()
[docs]def edit(mal, args): """Edit an entry in the users list, if it was present. Notify otherwise.""" changes = dict() for field in ['score', 'status', 'tags', 'add_tags']: attr = getattr(args, field) if attr is not None: changes[field] = attr # turn list of tags into a single string if needed for field in ['tags', 'add_tags']: if field in changes.keys(): changes[field] = ' '.join(changes[field]) core.edit(mal, args.anime_regex.lower(), changes)