From edd8e15978b1d08938f363f48339fa691776afe7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 23 Sep 2024 14:59:00 +0200 Subject: [PATCH] freetube.profiles --- rwx/sw/freetube/profiles.py | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 rwx/sw/freetube/profiles.py diff --git a/rwx/sw/freetube/profiles.py b/rwx/sw/freetube/profiles.py new file mode 100644 index 0000000..ffb0adc --- /dev/null +++ b/rwx/sw/freetube/profiles.py @@ -0,0 +1,45 @@ +"""FreeTube profiles.""" + +from rwx import Class + +from .channels import Channel + + +class Profile(Class): + """FreeTube profile.""" + + def __init__(self, uid: str, name: str) -> None: + """Set uid & name. + + :param uid: unique identifier + :type uid: str + :param name: label + :type name: str + """ + self.id = uid + self.name = name + self.channels: list[Channel] = [] + + def add(self, channel: Channel) -> None: + """Add channel. + + :param channel: channel to add + :type channel: Channel + """ + self.channels.append(channel) + + def to_db(self) -> str: + """Return identifier, name & channels. + + :rtype: str + """ + channels = ",".join([channel.to_db() for channel in self.channels]) + return f"""\ +{{\ +"_id":"{self.id}"\ +,\ +"name":"{self.name}"\ +,\ +"subscriptions":[{channels}]\ +}}\ +"""