-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdatabase.py
35 lines (31 loc) · 1.3 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def get_version_name_for_database(version_name: str):
"""This function prepares the version_name to be usable in the database as art of a table's name"""
version_name = version_name if "Unnamed" not in version_name else ""
version_name = version_name.strip().title().replace(" ", "").replace("-", "").replace("/", "_").replace("#", "") \
.strip(".")
return version_name.upper()
def get_standard_name_for_database(standard_name):
"""
This function prepares the standard_name to be usable in the database as part of a table's name
:param: standard_name: The standard_name to sanitize
:type standard_name: str
"""
if " " in standard_name:
tokens = standard_name.split(" ")
if "+" in tokens[1]:
# The "added" entries are already present in the dict
standard_name = tokens[0]
elif len(tokens) > 2 and "/" in tokens[-1]:
standard_name = tokens[0] + tokens[-1].replace("/", "_")
return standard_name.strip(")").upper()
def get_standardized_level(level):
"""
Takes a level in input and returns it after removing °,* and trailing spaces
:param level:
:type level: str
:return:
"""
if isinstance(level, str):
return level.replace("*", "").replace("°", "").strip()
else:
return ""