utils.py 518 B

1234567891011121314151617181920212223
  1. import random
  2. import string
  3. import urllib.parse
  4. from unidecode import unidecode
  5. def random_string(length=10):
  6. """Generate a random string of fixed length """
  7. letters = string.ascii_lowercase
  8. return "".join(random.choice(letters) for _ in range(length))
  9. def convert_to_id(s: str):
  10. """convert a string to id-like: remove space, remove special accent"""
  11. s = s.replace(" ", "")
  12. s = s.lower()
  13. s = unidecode(s)
  14. return s
  15. def encode_url(url):
  16. return urllib.parse.quote(url, safe="")