mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
rewrite remove duplicates to retain tracks with highest bitrate
+ bump fuzzy search cutoff to 90 + remove unicodes from fuzzy search texts
This commit is contained in:
+28
-29
@@ -1,55 +1,54 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def date_string_to_time_passed(prev_date: str) -> str:
|
||||
"""
|
||||
Converts a date string to time passed. eg. 2 minutes ago, 1 hour ago, yesterday, 2 days ago, 2 weeks ago, etc.
|
||||
"""
|
||||
|
||||
now = datetime.now()
|
||||
then = datetime.strptime(prev_date, "%Y-%m-%d %H:%M:%S")
|
||||
now = datetime.now(timezone.utc)
|
||||
then = datetime.strptime(prev_date, "%Y-%m-%d %H:%M:%S").replace(
|
||||
tzinfo=timezone.utc
|
||||
)
|
||||
|
||||
diff = now - then
|
||||
days = diff.days
|
||||
seconds = diff.total_seconds()
|
||||
|
||||
if days < 0:
|
||||
if seconds < 0:
|
||||
return "in the future"
|
||||
|
||||
if days == 0:
|
||||
seconds = diff.seconds
|
||||
if seconds < 15:
|
||||
return "now"
|
||||
|
||||
if seconds < 15:
|
||||
return "now"
|
||||
if seconds < 60:
|
||||
return f"{int(seconds)} seconds ago"
|
||||
|
||||
if seconds < 60:
|
||||
return str(seconds) + " seconds ago"
|
||||
if seconds < 3600:
|
||||
return f"{int(seconds // 60)} minutes ago"
|
||||
|
||||
if seconds < 3600:
|
||||
return str(seconds // 60) + " minutes ago"
|
||||
if seconds < 86400:
|
||||
return f"{int(seconds // 3600)} hours ago"
|
||||
|
||||
return str(seconds // 3600) + " hours ago"
|
||||
days = diff.days
|
||||
|
||||
if days == 1:
|
||||
return "yesterday"
|
||||
|
||||
if days < 7:
|
||||
return str(days) + " days ago"
|
||||
return f"{days} days ago"
|
||||
|
||||
if days < 14:
|
||||
return "1 week ago"
|
||||
|
||||
if days < 30:
|
||||
if days < 14:
|
||||
return "1 week ago"
|
||||
return f"{int(days // 7)} weeks ago"
|
||||
|
||||
if days < 60:
|
||||
return "1 month ago"
|
||||
|
||||
return str(days // 7) + " weeks ago"
|
||||
if days < 365:
|
||||
if days < 60:
|
||||
return "1 month ago"
|
||||
return f"{int(days // 30)} months ago"
|
||||
|
||||
return str(days // 30) + " months ago"
|
||||
if days > 365:
|
||||
if days < 730:
|
||||
return "1 year ago"
|
||||
|
||||
return str(days // 365) + " years ago"
|
||||
|
||||
return "I honestly don't know"
|
||||
if days < 730:
|
||||
return "1 year ago"
|
||||
|
||||
return f"{int(days // 365)} years ago"
|
||||
|
||||
Reference in New Issue
Block a user