-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
39 lines (32 loc) · 964 Bytes
/
util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: utf-8 -*-
# Generic/Built-in
from importlib import util
from datetime import datetime
def import_file(module_name: str, path: str):
"""
Imports a module from a file
Parameters
----------
module_name : str
name of the module to be imported
path : str
absolute path to the module
"""
spec = util.spec_from_file_location(module_name, path)
module = util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
def get_time():
"""
Returns the current time as string with format 'Y-m-d H:M:S'
"""
return datetime.now().strftime('%Y-%m-%d %H:%M:%S')
def format_uuid(uuid: str):
"""
Returns UUID formatted according to https://tools.ietf.org/html/rfc4122#section-3 (8-4-4-4-12)
Parameters
----------
module_name : str
unformatted UUID
"""
return f'{uuid[0:8]:s}-{uuid[8:12]:s}-{uuid[12:16]:s}-{uuid[16:20]:s}-{uuid[20:32]:s}'