Skip to content

Commit

Permalink
Merge pull request #102 from ryukinix/release/v0.4.0
Browse files Browse the repository at this point in the history
Release v0.4.0
  • Loading branch information
ryukinix authored Sep 13, 2018
2 parents ae178da + cf0281e commit 9059b0a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@
version from `mal.__version__` variable.
* Note: old users should fix date_format on ~/.config/mal/myanimelist.ini
manually changing from %%d-%%m-%%Y to %d-%m-%Y.
- v0.4.0
* Add edit command
* Fix date
* Option to disable animation in config
* Refactor docs
* Add basic tests covering the API
* Handle XML ParserError exception as easter egg (MAL API is DEAD anyway)
2 changes: 1 addition & 1 deletion mal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
#

__version__ = '0.4.0a0'
__version__ = '0.4.0'
__author__ = 'Manoel Vilela'
__email__ = '[email protected]'
__url__ = 'https://github.com/ryukinix/mal'
5 changes: 4 additions & 1 deletion mal/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from decorating import animated

# self-package
from mal.utils import checked_connection, checked_regex
from mal.utils import checked_connection, checked_regex, checked_cancer
from mal import setup


Expand Down Expand Up @@ -71,6 +71,7 @@ def login(cls, config):

return mal

@checked_cancer
@checked_connection
@animated('searching in database')
def search(self, query):
Expand All @@ -89,6 +90,7 @@ def search(self, query):
elements = ET.fromstring(r.text)
return [dict((attr.tag, attr.text) for attr in el) for el in elements]

@checked_cancer
@checked_connection
@animated('preparing animes')
def list(self, status='all', type='anime', extra=False, stats=False, user=None):
Expand Down Expand Up @@ -157,6 +159,7 @@ def find(self, regex, status='all', extra=False, user=None):
result.append(value)
return result

@checked_cancer
@checked_connection
@animated('updating')
def update(self, item_id, entry, action="update"):
Expand Down
20 changes: 20 additions & 0 deletions mal/utils.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
from functools import wraps
from sre_constants import error as BadRegexError
import xml.etree

# 3rd party
from decorating.animation import AnimatedDecorator
Expand Down Expand Up @@ -76,6 +77,25 @@ def wrapper(*args, **kwargs):
return wrapper


def checked_cancer(func):
"""Wrap the function in a try/except to catch and handle a BadRegexError."""
@wraps(func) # keeps the wrapped function's name and docstring intact
def wrapper(*args, **kwargs):
result = None
try:
result = func(*args, **kwargs)
except xml.etree.ElementTree.ParseError:
if AnimatedDecorator.spinner.running:
AnimatedDecorator.stop()
print_error('XMLParseError', 'Invalid API Response', 'reason: MAL IS DEAD')
sys.exit(1)

return result
return wrapper




def checked_connection(func):
"""Wrap the function in a try/except to catch and handle a ConnectionError."""
@wraps(func) # keeps the wrapped function's name and docstring intact
Expand Down

0 comments on commit 9059b0a

Please sign in to comment.