zcash-grant-system/backend/grant/utils/misc.py

39 lines
756 B
Python
Raw Normal View History

2018-09-10 09:55:26 -07:00
import datetime
import time
import random
import string
2018-11-16 08:16:52 -08:00
import re
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()))
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))
def from_zat(zat: int):
return zat / 100000000
def to_zat(zec: float):
return zec * 100000000