utils.py 438 B

123456789101112131415161718192021222324
  1. import hashlib
  2. import json
  3. import re
  4. from types import SimpleNamespace
  5. class Namespace(SimpleNamespace):
  6. def __contains__(self, key):
  7. return hasattr(self, key)
  8. def parse_json(text: str):
  9. return json.loads(text, object_hook=lambda d: Namespace(**d))
  10. def hash(text: str):
  11. return hashlib.md5(text.encode("utf-8")).hexdigest()
  12. def remove_brackets(string: str):
  13. return re.sub(r" ?\(.+\)", "", string).strip()