From 19153b3bc1f7372b2142f1ec403afb87012f003b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 13:04:56 +0200 Subject: [PATCH] freetube.db --- rwx/sw/freetube/db.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rwx/sw/freetube/db.py diff --git a/rwx/sw/freetube/db.py b/rwx/sw/freetube/db.py new file mode 100644 index 0000000..4b3f56b --- /dev/null +++ b/rwx/sw/freetube/db.py @@ -0,0 +1,20 @@ +"""Handle FreeTube db.""" + +def to_db(value: object) -> str: + """Render value as string. + + :param value: value to render + :type value: object + :rtype: str + """ + match value: + case bool(): + text = str(value).lower() + case dict(): + sub = ",".join([f'"{i}":{to_db(v)}' for i, v in value.items()]) + text = f"{{{sub}}}" + case float() | str(): + text = f'"{value}"' + case _: + text = str(value) + return text