redis connection + queue
This commit is contained in:
2
entity/__init__.py
Normal file
2
entity/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .queue import Queue
|
||||
from .entry import Entry
|
6
entity/entry.py
Normal file
6
entity/entry.py
Normal file
@ -0,0 +1,6 @@
|
||||
class Entry:
|
||||
def __init__(self, entry_info) -> None:
|
||||
self.title: str = entry_info["title"]
|
||||
self.artist: str = entry_info["artist"]
|
||||
self.thumbnail: str = entry_info["thumbnail"]
|
||||
self.requester: str = entry_info["requester"]
|
23
entity/queue.py
Normal file
23
entity/queue.py
Normal file
@ -0,0 +1,23 @@
|
||||
from entry import Entry
|
||||
|
||||
|
||||
class Queue:
|
||||
def __init__(self) -> None:
|
||||
self._queue: list[Entry] = []
|
||||
self.cursor = 0
|
||||
|
||||
def append(self, entry: Entry) -> None:
|
||||
self._queue.append(entry)
|
||||
|
||||
def remove(self, index: int) -> Entry | None:
|
||||
if 0 < index < len(self._queue):
|
||||
return self._queue.pop()
|
||||
|
||||
def move(self, frm: int, to: int) -> None:
|
||||
if 0 < frm < len(self._queue) and 0 < to < len(self._queue) and frm != to:
|
||||
self._queue.insert(to, self._queue.pop(frm))
|
||||
|
||||
def __getitem__(self, index: int) -> Entry | None:
|
||||
if index < 0 or index > len(self._queue):
|
||||
return None
|
||||
return self._queue[index]
|
Reference in New Issue
Block a user