2022-09-15 13:14:55 +02:00
|
|
|
import time
|
2021-02-20 21:37:31 +01:00
|
|
|
from datetime import timedelta
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
import humanize
|
|
|
|
|
2022-09-15 13:14:55 +02:00
|
|
|
from fittrackee import db
|
|
|
|
|
2021-02-20 21:37:31 +01:00
|
|
|
|
|
|
|
def get_readable_duration(duration: int, locale: Optional[str] = None) -> str:
|
|
|
|
"""
|
|
|
|
Return readable and localized duration from duration in seconds
|
|
|
|
"""
|
|
|
|
if locale is None:
|
|
|
|
locale = 'en'
|
|
|
|
if locale != 'en':
|
|
|
|
try:
|
|
|
|
_t = humanize.i18n.activate(locale) # noqa
|
|
|
|
except FileNotFoundError:
|
|
|
|
locale = 'en'
|
|
|
|
readable_duration = humanize.naturaldelta(timedelta(seconds=duration))
|
|
|
|
if locale != 'en':
|
|
|
|
humanize.i18n.deactivate()
|
|
|
|
return readable_duration
|
2022-09-15 13:14:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def clean(sql: str, days: int) -> int:
|
|
|
|
limit = int(time.time()) - (days * 86400)
|
|
|
|
result = db.engine.execute(sql, {'limit': limit})
|
|
|
|
return result.rowcount
|