PythonRMV/pyrmv/utility/weekdays_bitmask.py

21 lines
754 B
Python
Raw Normal View History

from typing import OrderedDict
2022-09-23 18:12:18 +03:00
def weekdays_bitmask(data: OrderedDict[str, bool]) -> str:
"""Convert ordered dict with weekdays to a bitmask.
### Args:
* data (OrderedDict[str, bool]): OrderedDict formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)
### Returns:
* str: _description_
"""
output = ""
if len(data) != 7:
raise ValueError("OrderedDict must be formatted as follows: OrderedDict(Monday=bool, Tuesday=bool, Wednesday=bool, Thursday=bool, Friday=bool, Saturday=bool, Sunday=bool)")
for day in data:
if data[day]:
output += "1"
else:
output += "0"
return output