mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-04 20:43:04 +00:00
add routes to get all albums and artists with sort
+ rewrite load all albums + artist logic with itertools.groupby + add a function to convert seconds to string
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
import locale
|
||||
|
||||
# Set to user's default locale:
|
||||
locale.setlocale(locale.LC_ALL, "")
|
||||
|
||||
# Or set to a specific locale:
|
||||
# locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
|
||||
|
||||
|
||||
def format_number(number: float) -> str:
|
||||
return locale.format_string("%d", number, grouping=True)
|
||||
|
||||
@@ -25,3 +25,23 @@ def date_string_to_time_passed(prev_date: str) -> str:
|
||||
diff = now - then
|
||||
now = pendulum.now()
|
||||
return now.subtract(seconds=diff).diff_for_humans()
|
||||
|
||||
|
||||
def seconds_to_time_string(seconds):
|
||||
"""
|
||||
Converts seconds to a time string. e.g. 1 hour 2 minutes, 1 hour 2 seconds, 1 hour, 1 minute 2 seconds, etc.
|
||||
"""
|
||||
hours = seconds // 3600
|
||||
minutes = (seconds % 3600) // 60
|
||||
remaining_seconds = seconds % 60
|
||||
|
||||
if hours > 0:
|
||||
if minutes > 0:
|
||||
return f"{hours} hr{'s' if hours > 1 else ''}, {minutes} minute{'s' if minutes > 1 else ''}"
|
||||
|
||||
return f"{hours} hr{'s' if hours > 1 else ''}"
|
||||
|
||||
if minutes > 0:
|
||||
return f"{minutes} minute{'s' if minutes > 1 else ''}"
|
||||
|
||||
return f"{remaining_seconds} second{'s' if remaining_seconds > 1 else ''}"
|
||||
|
||||
Reference in New Issue
Block a user