refactor multi-line-to-line normalisation to utils.parse.line_normalise(), use it in rss.py

closes #174
This commit is contained in:
jesopo 2019-10-10 10:32:47 +01:00
parent cf1002a2a9
commit 0331b763ff
3 changed files with 8 additions and 6 deletions

View file

@ -18,7 +18,8 @@ class Module(ModuleManager.BaseModule):
self.bot.get_setting("rss-interval", RSS_INTERVAL))
def _format_entry(self, server, feed_title, entry, shorten):
title = utils.http.strip_html(entry["title"])
title = utils.parse.line_normalise(utils.http.strip_html(
entry["title"]))
author = entry.get("author", None)
author = " by %s" % author if author else ""

View file

@ -7,11 +7,7 @@ def _timestamp(dt):
return "%s %s ago" % (since, unit)
def _normalise(tweet):
while " " in tweet:
tweet = tweet.replace(" ", " ")
lines = [line.strip() for line in tweet.split("\n")]
lines = list(filter(None, lines))
return html.unescape(" ".join(lines))
return html.unescape(utils.parse.line_normalise(tweet))
def _tweet(exports, server, tweet, from_url):
linked_id = tweet.id

View file

@ -1,4 +1,5 @@
import io, typing
from src import utils
COMMENT_TYPES = ["#", "//"]
def hashflags(filename: str
@ -79,3 +80,7 @@ def try_int(s: str) -> typing.Optional[int]:
return int(s)
except ValueError:
return None
def line_normalise(s: str) -> str:
lines = list(filter(None, [line.strip() for line in s.split("\n")]))
return " ".join(line.replace(" ", " ") for line in lines)