INNER CODE UNIT · Python
extract_colors
wikimedia/apps-android-wikipedia · scripts/generate-codex-colors.py:37
def extract_colors(color_data, token_type, dark_mode = False):
results = {}
color_section = color_data.get('color', color_data)
for name, color_info in color_section.items():
if (isinstance(color_info, dict)
and "attributes" in color_info
and "type" in color_info["attributes"]
and (color_info["attributes"]["type"] in ["base", "mode"] if dark_mode
else color_info["attributes"]["type"] == token_type)):
if token_type != "theme":
if ("original" in color_info
and "value" in color_info["original"]):
original_value = color_info["original"]["value"]
# Extract rawColor name from the value
match = re.search(r'color\.(\w+)', original_value)
if match:
pascal_names = to_camel_case(name)