diff --git a/commands.py b/commands.py index f70ad71..90d2ac6 100644 --- a/commands.py +++ b/commands.py @@ -1,4 +1,5 @@ import datetime +import unicodedata import dateutil.parser import requests @@ -171,9 +172,15 @@ class Commands(object): return clip def query_cheese_com(self, query): + def remove_accents(s): + s = unicodedata.normalize('NFKD', s) + return ''.join([c for c in s if not unicodedata.combining(c)]) cc = CheeseCom() try: - result = cc.query(query) + try: + result = cc.query(query) + except CheeseComError: + result = cc.query(remove_accents(query)) except CheeseComError: raise CommandError('couldn\'t find exact match on cheese.com') else: diff --git a/services/cheesecom.py b/services/cheesecom.py index 12354a3..b8c2d4b 100644 --- a/services/cheesecom.py +++ b/services/cheesecom.py @@ -19,6 +19,8 @@ class CheeseCom(object): d = pq(r.content) if not r.history: url = d('div[class~="cheese-item"]').eq(0).find('a').eq(0).attr('href') + if not url: + raise CheeseComError('Not found') r = requests.get(BASE_URL + url) d = pq(r.content) summary = []