Passed
Push — main ( f35407...df09ae )
by Sat CFDI
01:46
created

satdigitalinvoice.utils.to_uuid()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
import base64
2
import logging
3
import random
4
from datetime import datetime
5
from uuid import UUID
6
7
8
def to_uuid(s):
9
    try:
10
        return UUID(s)
11
    except ValueError:
12
        return None
13
14
15
def random_string():
16
    hash = random.randbytes(32)
17
    res = base64.urlsafe_b64encode(hash).decode()
18
    return res.rstrip("=")
19
20
21
def add_file_handler():
22
    fh = logging.FileHandler(
23
        f'.data/errors.log',
24
        mode='a'
25
    )
26
    fh.setLevel(logging.ERROR)
27
    formatter = logging.Formatter('%(asctime)s - %(message)s')
28
    fh.setFormatter(formatter)
29
    logging.root.addHandler(fh)
30
31
32
def convert_ans1_date(ans1_date):
33
    return datetime.strptime(ans1_date.decode('utf-8'), '%Y%m%d%H%M%SZ')