2018-09-10 09:55:26 -07:00
|
|
|
import datetime
|
|
|
|
import time
|
2018-11-02 09:07:06 -07:00
|
|
|
import random
|
|
|
|
import string
|
2018-11-16 08:16:52 -08:00
|
|
|
import re
|
2018-11-02 09:07:06 -07:00
|
|
|
from grant.settings import SITE_URL
|
2018-09-10 09:55:26 -07:00
|
|
|
|
|
|
|
epoch = datetime.datetime.utcfromtimestamp(0)
|
|
|
|
|
|
|
|
|
|
|
|
def dt_from_ms(ms):
|
|
|
|
return datetime.datetime.utcfromtimestamp(ms / 1000.0)
|
|
|
|
|
|
|
|
|
|
|
|
def dt_to_ms(dt):
|
|
|
|
delta = dt - epoch
|
|
|
|
return int(delta.total_seconds() * 1000)
|
|
|
|
|
|
|
|
|
|
|
|
def dt_to_unix(dt):
|
|
|
|
return int(time.mktime(dt.timetuple()))
|
2018-11-02 09:07:06 -07:00
|
|
|
|
|
|
|
def gen_random_code(length=32):
|
|
|
|
return ''.join(
|
|
|
|
[random.choice(string.ascii_letters + string.digits) for n in range(length)]
|
|
|
|
)
|
|
|
|
|
|
|
|
def make_url(path: str):
|
|
|
|
return f'{SITE_URL}{path}'
|
2018-11-16 08:16:52 -08:00
|
|
|
|
|
|
|
def is_email(email: str):
|
|
|
|
return bool(re.match(r"[^@]+@[^@]+\.[^@]+", email))
|
2019-01-09 11:35:37 -08:00
|
|
|
|
|
|
|
def from_zat(zat: int):
|
|
|
|
return zat / 100000000
|
|
|
|
|
2019-01-09 11:45:16 -08:00
|
|
|
def to_zat(zec: float):
|
2019-01-09 11:35:37 -08:00
|
|
|
return zec * 100000000
|