From: Vincent Le Gallic Date: Mon, 14 Apr 2014 06:58:20 +0000 (+0200) Subject: On droppe les espaces insécables dans les auteurs X-Git-Url: http://gitweb.pimeys.fr/?p=bots%2Fparrot.git;a=commitdiff_plain;h=d2edf940c5e7cf78465954534040ff2406cc0c7a On droppe les espaces insécables dans les auteurs --- diff --git a/quotes.py b/quotes.py index fa9ac0a..08cac11 100644 --- a/quotes.py +++ b/quotes.py @@ -13,11 +13,16 @@ import config quote_matcher = re.compile(config.quote_regexp, flags=re.UNICODE) quote_matcher_with_timestamp = re.compile(config.quote_regexp_with_timestamp, flags=re.UNICODE) +spaces_matcher = re.compile(u"\s", flags=re.U) def get_now(): """ Renvoie la date actuelle """ return datetime.datetime(*time.localtime()[:6]) +def sanitize_author(raw): + """Proprifie l'auteur : enlève les espaces insécables.""" + return spaces_matcher.sub(u" ", raw) + class Quote(object): """ Une citation """ def __init__(self, author, content, timestamp=None): @@ -25,7 +30,7 @@ class Quote(object): timestamp = get_now() elif isinstance(timestamp, basestring): timestamp = datetime.datetime(*time.strptime(timestamp, u"%Y-%m-%d_%H:%M:%S")[:6]) - self.author = author + self.author = sanitize_author(author) self.content = content self.timestamp = timestamp