Skip to content

Commit

Permalink
refactor: refactor folder as 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
EstrellaXD committed Jun 28, 2023
1 parent 4c94a51 commit 58bff6c
Show file tree
Hide file tree
Showing 101 changed files with 252 additions and 115 deletions.
8 changes: 4 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ coverage.xml
../.pytest_cache
.hypothesis

src/module/tests
src/module/conf/const_dev.py
backend/src/module/tests
backend/src/module/conf/const_dev.py
config/bangumi.json/config/bangumi.json
/docs
/.github
Expand All @@ -33,8 +33,8 @@ config/bangumi.json/config/bangumi.json
dist.zip
data
config
/src/config
/src/data
/backend/src/config
/backend/src/data
.pytest_cache
test
.env
Expand Down
20 changes: 10 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,18 @@ cython_debug/
#.idea/

# Custom
/src/test.py
/backend/src/test.py

/src/module/run_debug.sh
/src/module/debug_run.sh
/src/module/__version__.py
/src/data/
/backend/src/module/run_debug.sh
/backend/src/module/debug_run.sh
/backend/src/module/__version__.py
/backend/src/data/

/src/module/conf/config_dev.ini
/backend/src/module/conf/config_dev.ini

test.*
.run
/src/templates/
/src/config/
/src/debuger.py
/src/dist.zip
/backend/src/templates/
/backend/src/config/
/backend/src/debuger.py
/backend/src/dist.zip
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ RUN apk add --no-cache \
/root/.cache \
/tmp/*

COPY --chmod=755 src/. .
COPY --chmod=755 src/docker /
COPY --chmod=755 backend/src/. .
COPY --chmod=755 backend/src/docker /

ENTRYPOINT [ "/init" ]

Expand Down
8 changes: 8 additions & 0 deletions backend/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
language: python

# TODO: add ruff lint check before committing
63 changes: 63 additions & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[tool.ruff]
select = [
# pycodestyle(E): https://beta.ruff.rs/docs/rules/#pycodestyle-e-w
"E",
# Pyflakes(F): https://beta.ruff.rs/docs/rules/#pyflakes-f
"F",
# isort(I): https://beta.ruff.rs/docs/rules/#isort-i
"I"
]
ignore = [
# E501: https://beta.ruff.rs/docs/rules/line-too-long/
'E501',
# F401: https://beta.ruff.rs/docs/rules/unused-import/
# avoid unused imports lint in `__init__.py`
'F401',
]

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]
per-file-ignores = {}

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.10.
target-version = "py310"

[tool.ruff.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10

[tool.black]
line-length = 88
target-version = ['py310', 'py311']
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ def locked(func):
def wrapper(*args, **kwargs):
with lock:
return func(*args, **kwargs)
return wrapper

return wrapper
File renamed without changes.
9 changes: 2 additions & 7 deletions src/module/api/auth.py → backend/src/module/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ async def login(form_data: OAuth2PasswordRequestForm = Depends()):
username = form_data.username
password = form_data.password
auth_user(username, password)
token = create_access_token(
data={"sub": username}, expires_delta=timedelta(days=1)
)
token = create_access_token(data={"sub": username}, expires_delta=timedelta(days=1))

return {"access_token": token, "token_type": "bearer", "expire": 86400}

Expand All @@ -32,10 +30,7 @@ async def refresh(current_user: User = Depends(get_current_user)):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
)
token = create_access_token(
data = {"sub": current_user.username}

)
token = create_access_token(data={"sub": current_user.username})
return {"access_token": token, "token_type": "bearer", "expire": 86400}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

logger = logging.getLogger(__name__)


@router.get(
"/api/v1/bangumi/getAll", tags=["bangumi"], response_model=list[BangumiData]
)
Expand Down Expand Up @@ -50,7 +51,9 @@ async def update_rule(data: BangumiData, current_user=Depends(get_current_user))


@router.delete("/api/v1/bangumi/deleteRule/{bangumi_id}", tags=["bangumi"])
async def delete_rule(bangumi_id: str, file: bool = False, current_user=Depends(get_current_user)):
async def delete_rule(
bangumi_id: str, file: bool = False, current_user=Depends(get_current_user)
):
if not current_user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED, detail="invalid token"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ def match_list(self, torrent_list: list, rss_link: str) -> list:
if match_data.get("title_raw") in torrent.name:
if rss_link not in match_data.get("rss_link"):
match_data["rss_link"] += f",{rss_link}"
self.update_rss(match_data.get("title_raw"), match_data.get("rss_link"))
self.update_rss(
match_data.get("title_raw"), match_data.get("rss_link")
)
if not match_data.get("poster_link"):
self.update_poster(match_data.get("title_raw"), torrent.poster_link)
self.update_poster(
match_data.get("title_raw"), torrent.poster_link
)
torrent_list.pop(i)
break
else:
Expand Down Expand Up @@ -217,7 +221,7 @@ def __check_list_exist(self, data_list: list[BangumiData]):
return False


if __name__ == '__main__':
if __name__ == "__main__":
with BangumiDatabase() as db:
name = "久保"
print(db.match_poster(name))
print(db.match_poster(name))
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ def _delete_all(self, table_name: str):

def _delete(self, table_name: str, condition: dict):
condition_sql = " AND ".join([f"{key} = :{key}" for key in condition.keys()])
self._cursor.execute(f"DELETE FROM {table_name} WHERE {condition_sql}", condition)
self._cursor.execute(
f"DELETE FROM {table_name} WHERE {condition_sql}", condition
)
self._conn.commit()

def _search(self, table_name: str, keys: list[str] | None = None, condition: dict = None):
def _search(
self, table_name: str, keys: list[str] | None = None, condition: dict = None
):
if keys is None:
select_sql = "*"
else:
Expand All @@ -112,20 +116,25 @@ def _search(self, table_name: str, keys: list[str] | None = None, condition: dic
self._cursor.execute(f"SELECT {select_sql} FROM {table_name}")
else:
custom_condition = condition.pop("_custom_condition", None)
condition_sql = " AND ".join([f"{key} = :{key}" for key in condition.keys()]) + (
f" AND {custom_condition}" if custom_condition else ""
)
condition_sql = " AND ".join(
[f"{key} = :{key}" for key in condition.keys()]
) + (f" AND {custom_condition}" if custom_condition else "")
self._cursor.execute(
f"SELECT {select_sql} FROM {table_name} WHERE {condition_sql}", condition
f"SELECT {select_sql} FROM {table_name} WHERE {condition_sql}",
condition,
)

def _search_data(self, table_name: str, keys: list[str] | None = None, condition: dict = None) -> dict:
def _search_data(
self, table_name: str, keys: list[str] | None = None, condition: dict = None
) -> dict:
if keys is None:
keys = self.__get_table_columns(table_name)
self._search(table_name, keys, condition)
return dict(zip(keys, self._cursor.fetchone()))

def _search_datas(self, table_name: str, keys: list[str] | None = None, condition: dict = None) -> list[dict]:
def _search_datas(
self, table_name: str, keys: list[str] | None = None, condition: dict = None
) -> list[dict]:
if keys is None:
keys = self.__get_table_columns(table_name)
self._search(table_name, keys, condition)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def add_category(self, category):

@qb_connect_failed_wait
def torrents_info(self, status_filter, category, tag=None):
return self._client.torrents_info(status_filter=status_filter, category=category, tag=tag)
return self._client.torrents_info(
status_filter=status_filter, category=category, tag=tag
)

def torrents_add(self, urls, save_path, category, torrent_files=None):
resp = self._client.torrents_add(
Expand All @@ -87,7 +89,7 @@ def torrents_add(self, urls, save_path, category, torrent_files=None):
torrent_files=torrent_files,
save_path=save_path,
category=category,
use_auto_torrent_management=False
use_auto_torrent_management=False,
)
return resp == "Ok."

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ def collect_season(self, data: BangumiData, link: str = None, proxy: bool = Fals
torrents = st.get_torrents(link, _filter="|".join(data.filter))
torrent_files = None
if proxy:
torrent_files = [st.get_content(torrent.torrent_link) for torrent in torrents]
return self.add_season_torrents(data=data, torrents=torrents, torrent_files=torrent_files)
torrent_files = [
st.get_content(torrent.torrent_link) for torrent in torrents
]
return self.add_season_torrents(
data=data, torrents=torrents, torrent_files=torrent_files
)

def subscribe_season(self, data: BangumiData):
with BangumiDatabase() as db:
Expand All @@ -57,5 +61,3 @@ def eps_complete():
sc.collect_season(data)
data.eps_collect = True
bd.update_list(datas)


Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def gen_path(
elif method == "advance":
return f"{bangumi_name} S{season}E{episode}{file_info.suffix}"
elif method == "normal":
logger.warning(
"[Renamer] Normal rename method is deprecated."
)
logger.warning("[Renamer] Normal rename method is deprecated.")
return file_info.media_path
elif method == "subtitle_pn":
return f"{file_info.title} S{season}E{episode}.{file_info.language}{file_info.suffix}"
Expand Down Expand Up @@ -73,10 +71,10 @@ def rename_file(
)
if renamed:
n = Notification(
official_title=bangumi_name,
season=ep.season,
episode=ep.episode,
)
official_title=bangumi_name,
season=ep.season,
episode=ep.episode,
)
return n
else:
logger.warning(f"[Renamer] {media_path} parse failed")
Expand Down Expand Up @@ -178,6 +176,7 @@ def rename(self) -> list[Notification]:

if __name__ == "__main__":
from module.conf import setup_logger

settings.log.debug_enable = True
setup_logger()
with Renamer() as renamer:
Expand Down
Loading

0 comments on commit 58bff6c

Please sign in to comment.