X-Git-Url: http://gitweb.pimeys.fr/?p=bots%2Fparrot.git;a=blobdiff_plain;f=quotes.py;h=08cac11f11368a8dec06db4f2bce6cd1ae0d8e54;hp=c1aca7617cbe1017cb4dc128c1b64b628e126a89;hb=d2edf940c5e7cf78465954534040ff2406cc0c7a;hpb=cf0848cb22e2dcf42846ce2d92b182b166e5fc59 diff --git a/quotes.py b/quotes.py index c1aca76..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 @@ -119,7 +124,7 @@ class QuoteDB(object): return l def search_authors(self, author=None, regexp=False): - """Renvoie la liste des auteur contenant ``author`` ou qui matchent la regexp.""" + """Renvoie la liste des auteurs contenant ``author`` ou qui matchent la regexp.""" if regexp: if author is None: author = ".*"