| 27 | |
| 28 | |
| 29 | class MyDB: |
| 30 | |
| 31 | def __init__(self, object_driver): |
| 32 | self.driver = object_driver |
| 33 | self.database = "neo4j" |
| 34 | |
| 35 | @staticmethod |
| 36 | def timestamp(): |
| 37 | return datetime.now(timezone.utc).isoformat(sep="T", timespec="milliseconds") |
| 38 | |
| 39 | @staticmethod |
| 40 | def bcf_time(any_datetime): |
| 41 | if isinstance(any_datetime, str): |
| 42 | datetime_any = parser.parse(any_datetime).astimezone(pytz.utc) |
| 43 | elif isinstance(any_datetime, type(datetime.now())): |
| 44 | datetime_any = any_datetime.astimezone(pytz.utc) |
| 45 | else: |
| 46 | return False |
| 47 | string_date = datetime_any.isoformat(sep="T", timespec="milliseconds") |
| 48 | return str(string_date) |
| 49 | |
| 50 | @staticmethod |
| 51 | def safe_path(path_name): |
| 52 | safe_path_name = "".join(x for x in path_name if x.isalnum() or "-") |
| 53 | return safe_path_name |
| 54 | |
| 55 | @staticmethod |
| 56 | def debug(endpoint: str, request, response): |
| 57 | print( |
| 58 | "\n\n\nEndpoint: ", |
| 59 | jsonpickle.dumps(endpoint), |
| 60 | "\nRequest: ", |
| 61 | jsonpickle.dumps(request), |
| 62 | "\nResponse: ", |
| 63 | jsonpickle.dumps(response), |
| 64 | ) |
| 65 | |
| 66 | @staticmethod |
| 67 | def node_to_json(node): |
| 68 | json = {} |
| 69 | for fields in node.items(): |
| 70 | json[fields[0]] = fields[1] |
| 71 | return json |
| 72 | |
| 73 | @staticmethod |
| 74 | def is_valid_uuid(uuid_to_test, version=4): |
| 75 | try: |
| 76 | uuid_obj = UUID(uuid_to_test, version=version) |
| 77 | except ValueError: |
| 78 | return False |
| 79 | return str(uuid_obj) == uuid_to_test |
| 80 | |
| 81 | @staticmethod |
| 82 | def new_uuid(): |
| 83 | try: |
| 84 | uuid_obj = uuid4() |
| 85 | except ValueError: |
| 86 | return False |