diff --git a/src/utils/sortgenerator.py b/src/utils/sortgenerator.py new file mode 100644 index 0000000..b6cf94b --- /dev/null +++ b/src/utils/sortgenerator.py @@ -0,0 +1,35 @@ +alphabet = "abcdefghijklmnopqrstuvwxyzäöüß" +alphabet = [c for c in alphabet] + + +def name_sort(name: str, index_len: int = 8) -> str: + """ + name_to_index converts a name to an index. + """ + name = name.lower() + sort_number = [] + for i, c in enumerate(name): + if i < index_len: + num = alphabet.index(c) + 1 + sort_number += str(num) + + res = "" + for i in sort_number: + res += str(i) + # get the first 8 characters + res = res[:index_len] + return res + + +def app_sort(app_id: int) -> str: + if not isinstance(app_id, int): + raise ValueError("app_id must be an integer") + if app_id >= 180: + raise ValueError("app_id must be smaller than 180") + length = 4 + app_id = str(app_id) + # left pad with zeros to length + app_id_length = len(app_id) + if app_id_length < length: + app_id = "0" * (length - app_id_length - 1) + app_id + "0" + return str(app_id)