68 lines
1.5 KiB
Python
68 lines
1.5 KiB
Python
from functools import wraps
|
|
from os import getenv
|
|
from typing import List
|
|
|
|
from pynyaata.types import Color, RemoteFile
|
|
|
|
|
|
def duplicate(remotes: List[RemoteFile]) -> List[RemoteFile]:
|
|
processed_ids: List[int] = []
|
|
dedup_remotes: List[RemoteFile] = []
|
|
|
|
for remote in remotes:
|
|
if remote.id not in processed_ids:
|
|
dedup_remotes.append(remote)
|
|
|
|
processed_ids.append(remote.id)
|
|
|
|
return dedup_remotes
|
|
|
|
|
|
def inactive(remotes: List[RemoteFile]) -> List[RemoteFile]:
|
|
return list(
|
|
filter(
|
|
lambda remote: remote.seeds != 0 or remote.downloads != 0,
|
|
remotes,
|
|
)
|
|
)
|
|
|
|
|
|
def blacklist(remotes: List[RemoteFile]) -> List[RemoteFile]:
|
|
BLACKLIST_WORDS = getenv("BLACKLIST_WORDS", "")
|
|
|
|
if not BLACKLIST_WORDS:
|
|
return remotes
|
|
else:
|
|
return list(
|
|
filter(
|
|
lambda remote: not any(
|
|
word in remote.name.lower() for word in BLACKLIST_WORDS.split(",")
|
|
),
|
|
remotes,
|
|
)
|
|
)
|
|
|
|
|
|
def danger(remotes: List[RemoteFile]) -> List[RemoteFile]:
|
|
return list(
|
|
filter(
|
|
lambda remote: remote.color != Color.DANGER,
|
|
remotes,
|
|
)
|
|
)
|
|
|
|
|
|
def filter_data(f):
|
|
@wraps(f)
|
|
async def wrapper(*args, **kwargs):
|
|
ret = await f(*args, **kwargs)
|
|
|
|
ret = duplicate(ret)
|
|
ret = inactive(ret)
|
|
ret = blacklist(ret)
|
|
ret = danger(ret)
|
|
|
|
return ret
|
|
|
|
return wrapper
|