32 lines
775 B
Python
32 lines
775 B
Python
from datetime import datetime
|
|
import secrets
|
|
import string
|
|
|
|
VALID_TOKEN_CHARS = string.digits + string.ascii_letters
|
|
|
|
|
|
def random_token():
|
|
return "".join(secrets.choice(VALID_TOKEN_CHARS) for i in range(8))
|
|
|
|
|
|
def file_date_human(num):
|
|
return datetime.fromtimestamp(num).strftime("%y-%m-%d")
|
|
|
|
|
|
def file_time_human(num):
|
|
return datetime.fromtimestamp(num).strftime("%y-%m-%d %H:%M")
|
|
|
|
|
|
def file_size_human(num, HTML=True):
|
|
space = " " if HTML else " "
|
|
for x in [space + "B", "KB", "MB", "GB", "TB"]:
|
|
if num < 1024.0:
|
|
if x == space + "B":
|
|
return "%d%s%s" % (num, space, x)
|
|
return "%3.1f%s%s" % (num, space, x)
|
|
num /= 1024.0
|
|
|
|
|
|
def file_size_MB(num):
|
|
return "{:,.2f}".format(num / (1024 * 1024))
|