mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-24 16:37:29 +00:00
Add publishedText to /channels/latest
This commit is contained in:
parent
c2a7bb907b
commit
0a6a07838d
@ -120,6 +120,7 @@ def extract_channel_latest(ucid):
|
||||
media_group = entry.find("{http://search.yahoo.com/mrss/}group")
|
||||
description = media_group.find("{http://search.yahoo.com/mrss/}description").text
|
||||
media_community = media_group.find("{http://search.yahoo.com/mrss/}community")
|
||||
published = int(dateutil.parser.isoparse(entry.find("{http://www.w3.org/2005/Atom}published").text).timestamp())
|
||||
results.append({
|
||||
"type": "video",
|
||||
"title": entry.find("{http://www.w3.org/2005/Atom}title").text,
|
||||
@ -131,7 +132,8 @@ def extract_channel_latest(ucid):
|
||||
"description": description,
|
||||
"descriptionHtml": add_html_links(escape_html_textcontent(description)),
|
||||
"viewCount": int(media_community.find("{http://search.yahoo.com/mrss/}statistics").attrib["views"]),
|
||||
"published": int(dateutil.parser.isoparse(entry.find("{http://www.w3.org/2005/Atom}published").text).timestamp()),
|
||||
"published": published,
|
||||
"publishedText": time_to_past_text(published),
|
||||
"lengthSeconds": None,
|
||||
"liveNow": None,
|
||||
"paid": None,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import configuration
|
||||
import datetime
|
||||
import re
|
||||
import time
|
||||
|
||||
def length_text_to_seconds(text):
|
||||
s = text.split(":")
|
||||
@ -164,3 +165,23 @@ def past_text_to_time(text):
|
||||
elif unit == "ye":
|
||||
multiplier = 365 * 24 * 60 * 60
|
||||
return int(datetime.datetime.now().timestamp()) - number * multiplier
|
||||
|
||||
def time_to_past_text(timestamp):
|
||||
now = int(time.time())
|
||||
diff = now - timestamp
|
||||
print(diff, type(diff))
|
||||
units = [
|
||||
["year", 365 * 24 * 60 * 60],
|
||||
["month", 30 * 24 * 60 * 60],
|
||||
["week", 7 * 24 * 60 * 60],
|
||||
["day", 24 * 60 * 60],
|
||||
["hour", 60 * 60],
|
||||
["minute", 60],
|
||||
["second", 1]
|
||||
]
|
||||
for index in range(len(units)):
|
||||
unit_name, unit_value = units[index]
|
||||
if diff > unit_value or index + 1 >= len(units):
|
||||
number = diff // unit_value
|
||||
plural_unit = unit_name if number == 1 else unit_name + "s"
|
||||
return "{} {} ago".format(number, plural_unit)
|
||||
|
Loading…
Reference in New Issue
Block a user