Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init_order(self) -> Iterable[Any]:
col_mapping: Dict[str, Column] = {
"id": Video.id,
"date": Video.publish_date,
"channel": Channel.displayname,
"title": Video.title,
"url": Video.yt_videoid,
"watched": Video.watched
}
for key in self._config["YTCC"]["orderBy"].split(","):
sort_spec = list(map(lambda s: s.strip().lower(), key.split(":")))
col = sort_spec[0]
desc = ""
if len(sort_spec) == 2:
desc = sort_spec[1]
column = unpack_or_raise(col_mapping.get(col),
BadConfigException(f"Cannot order by {key.strip()}"))
column = column.collate("NOCASE")
yield column.desc() if desc == "desc" else column
def get_channels(self) -> List[Channel]:
return self.session.query(Channel).order_by(Channel.displayname).all()
def rename_channel(self, oldname: str, newname: str) -> None:
"""Rename the given channel.
:param oldname: The name of the channel.
:param newname: The new name of the channel.
:raises ChannelDoesNotExistException: If the given channel does not exist.
:raises DuplicateChannelException: If new name already exists.
"""
query = self.session.query(Channel).filter(Channel.displayname == newname)
if query.one_or_none() is not None:
raise DuplicateChannelException()
try:
channel = self.session.query(Channel).filter(Channel.displayname == oldname).one()
channel.displayname = newname
except NoResultFound:
raise ChannelDoesNotExistException()