2019-05-27 13:52:08 +00:00
|
|
|
import datetime, html, time
|
|
|
|
from src import utils
|
|
|
|
|
|
|
|
def _timestamp(dt):
|
2020-11-05 05:45:40 +00:00
|
|
|
seconds_since = time.time()-dt.replace(tzinfo=datetime.timezone.utc).timestamp()
|
2020-02-24 10:18:55 +00:00
|
|
|
timestamp = utils.datetime.format.to_pretty_since(
|
2020-01-30 21:12:31 +00:00
|
|
|
seconds_since, max_units=2)
|
2020-01-28 15:31:49 +00:00
|
|
|
return "%s ago" % timestamp
|
2019-05-27 13:52:08 +00:00
|
|
|
|
2019-10-09 14:35:20 +00:00
|
|
|
def _normalise(tweet):
|
2019-10-10 09:32:47 +00:00
|
|
|
return html.unescape(utils.parse.line_normalise(tweet))
|
2019-10-09 14:35:20 +00:00
|
|
|
|
2019-10-08 13:21:15 +00:00
|
|
|
def _tweet(exports, server, tweet, from_url):
|
2019-05-27 13:52:08 +00:00
|
|
|
linked_id = tweet.id
|
|
|
|
username = tweet.user.screen_name
|
|
|
|
|
|
|
|
verified = ""
|
|
|
|
if tweet.user.verified:
|
|
|
|
verified = " %s" % utils.irc.color("✓", utils.consts.LIGHTBLUE)
|
|
|
|
|
|
|
|
tweet_link = "https://twitter.com/%s/status/%s" % (username,
|
|
|
|
linked_id)
|
|
|
|
|
2019-10-08 13:21:15 +00:00
|
|
|
short_url = ""
|
|
|
|
if not from_url:
|
2020-03-08 14:14:00 +00:00
|
|
|
short_url = exports.get("shorturl")(server, tweet_link)
|
2019-10-08 13:21:15 +00:00
|
|
|
short_url = " - %s" % short_url if short_url else ""
|
2019-05-27 13:52:08 +00:00
|
|
|
created_at = _timestamp(tweet.created_at)
|
|
|
|
|
|
|
|
# having to use hasattr here is nasty.
|
|
|
|
if hasattr(tweet, "retweeted_status"):
|
|
|
|
original_username = tweet.retweeted_status.user.screen_name
|
2019-07-15 13:27:37 +00:00
|
|
|
original_text = tweet.retweeted_status.full_text
|
2019-05-27 13:52:08 +00:00
|
|
|
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,
|
2019-10-09 14:35:20 +00:00
|
|
|
_normalise(original_text), short_url)
|
2019-05-27 13:52:08 +00:00
|
|
|
else:
|
|
|
|
return "(@%s%s, %s) %s%s" % (username, verified, created_at,
|
2019-10-09 14:35:20 +00:00
|
|
|
_normalise(tweet.full_text), short_url)
|
2019-05-27 13:52:08 +00:00
|
|
|
|