refactor multi-line-to-line normalisation to utils.parse.line_normalise(), use it in rss.py
closes #174
This commit is contained in:
parent
cf1002a2a9
commit
0331b763ff
3 changed files with 8 additions and 6 deletions
|
@ -18,7 +18,8 @@ class Module(ModuleManager.BaseModule):
|
||||||
self.bot.get_setting("rss-interval", RSS_INTERVAL))
|
self.bot.get_setting("rss-interval", RSS_INTERVAL))
|
||||||
|
|
||||||
def _format_entry(self, server, feed_title, entry, shorten):
|
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 = entry.get("author", None)
|
||||||
author = " by %s" % author if author else ""
|
author = " by %s" % author if author else ""
|
||||||
|
|
|
@ -7,11 +7,7 @@ def _timestamp(dt):
|
||||||
return "%s %s ago" % (since, unit)
|
return "%s %s ago" % (since, unit)
|
||||||
|
|
||||||
def _normalise(tweet):
|
def _normalise(tweet):
|
||||||
while " " in tweet:
|
return html.unescape(utils.parse.line_normalise(tweet))
|
||||||
tweet = tweet.replace(" ", " ")
|
|
||||||
lines = [line.strip() for line in tweet.split("\n")]
|
|
||||||
lines = list(filter(None, lines))
|
|
||||||
return html.unescape(" ".join(lines))
|
|
||||||
|
|
||||||
def _tweet(exports, server, tweet, from_url):
|
def _tweet(exports, server, tweet, from_url):
|
||||||
linked_id = tweet.id
|
linked_id = tweet.id
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import io, typing
|
import io, typing
|
||||||
|
from src import utils
|
||||||
|
|
||||||
COMMENT_TYPES = ["#", "//"]
|
COMMENT_TYPES = ["#", "//"]
|
||||||
def hashflags(filename: str
|
def hashflags(filename: str
|
||||||
|
@ -79,3 +80,7 @@ def try_int(s: str) -> typing.Optional[int]:
|
||||||
return int(s)
|
return int(s)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return None
|
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)
|
||||||
|
|
Loading…
Reference in a new issue