aboutsummaryrefslogtreecommitdiff
path: root/modules/tweets
diff options
context:
space:
mode:
authorGravatar jesopo2019-10-09 15:35:20 +0100
committerGravatar jesopo2019-10-09 15:35:20 +0100
commit5aba3f509e6e7a88f9ae6efc1735729297fa1701 (patch)
treecdaac8d136ae5fe0e1213faaff2bbdcfba5ebccf /modules/tweets
parentonly FORCE_SUCCESS for masterlogin when there's a permissions requirement (diff)
signature
format multi-line tweets on a single line using things like double spaces
Diffstat (limited to 'modules/tweets')
-rw-r--r--modules/tweets/format.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/modules/tweets/format.py b/modules/tweets/format.py
index 0a4926e4..8b84cba3 100644
--- a/modules/tweets/format.py
+++ b/modules/tweets/format.py
@@ -6,6 +6,13 @@ def _timestamp(dt):
since, unit = utils.time_unit(seconds_since)
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))
+
def _tweet(exports, server, tweet, from_url):
linked_id = tweet.id
username = tweet.user.screen_name
@@ -30,8 +37,8 @@ def _tweet(exports, server, tweet, from_url):
original_timestamp = _timestamp(tweet.retweeted_status.created_at)
return "(@%s%s (%s) retweeted @%s (%s)) %s%s" % (username, verified,
created_at, original_username, original_timestamp,
- html.unescape(original_text), short_url)
+ _normalise(original_text), short_url)
else:
return "(@%s%s, %s) %s%s" % (username, verified, created_at,
- html.unescape(tweet.full_text), short_url)
+ _normalise(tweet.full_text), short_url)