| Total Complexity | 5 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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') |