streamlabs-socketio-py/streamlabsio/models.py

23 lines
483 B
Python
Raw Normal View History

2022-11-13 10:07:08 +00:00
import re
from dataclasses import dataclass
def to_snake_case(s):
2025-01-20 13:32:36 +00:00
return re.sub(r'(?<!^)(?=[A-Z])', '_', s).lower()
2022-11-13 10:07:08 +00:00
def as_dataclass(identifier, data):
def attrs():
return list(to_snake_case(k) for k in data.keys())
return dataclass(
type(
2025-01-20 13:32:36 +00:00
f'{identifier.capitalize()}Dataclass',
2022-11-13 10:07:08 +00:00
(),
{
2025-01-20 13:32:36 +00:00
'attrs': attrs,
2022-11-13 10:07:08 +00:00
**{to_snake_case(k): v for k, v in data.items()},
},
)
)