mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-05-07 08:02:46 +08:00
init: 初始化
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.ruff_cache
|
||||
__pycache__
|
||||
10
Makefile
Normal file
10
Makefile
Normal file
@@ -0,0 +1,10 @@
|
||||
.PHONY: install lint
|
||||
|
||||
install:
|
||||
@echo "Installing dependencies..."
|
||||
@poetry install --no-root
|
||||
|
||||
fmt:
|
||||
@echo "Formatting..."
|
||||
@poetry run black .
|
||||
@poetry run ruff --fix .
|
||||
12
main.py
Normal file
12
main.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import asyncio
|
||||
|
||||
from bilibili_api import favorite_list
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
result = await favorite_list.get_video_favorite_list(9183758)
|
||||
print(result)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.get_event_loop().run_until_complete(main())
|
||||
1416
poetry.lock
generated
Normal file
1416
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
pyproject.toml
Normal file
21
pyproject.toml
Normal file
@@ -0,0 +1,21 @@
|
||||
[tool.poetry]
|
||||
name = "bili-sync"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["amtoaer <amtoaer@gmail.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.11"
|
||||
bilibili-api-python = {git = "https://github.com/amtoaer/bilibili-api.git", rev = "dev"}
|
||||
dataclasses-json = "0.6.2"
|
||||
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
black = "23.11.0"
|
||||
ruff = "0.1.6"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
46
settings.py
Normal file
46
settings.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from dataclasses import dataclass
|
||||
from dataclasses_json import DataClassJsonMixin
|
||||
from pathlib import Path
|
||||
from typing import Self
|
||||
|
||||
|
||||
@dataclass
|
||||
class Config(DataClassJsonMixin):
|
||||
sessiondata: str
|
||||
bili_jct: str
|
||||
buvid3: str
|
||||
dedeuserid: str
|
||||
ac_time_value: str
|
||||
favorite_ids: list
|
||||
path_mapper: dict
|
||||
|
||||
@staticmethod
|
||||
def load(path: Path | str) -> Self:
|
||||
if isinstance(path, str):
|
||||
path = Path(path)
|
||||
try:
|
||||
with path.open("r") as f:
|
||||
return Config.schema().loads(f.read())
|
||||
except Exception as e:
|
||||
raise ValueError(f"Failed to load config file: {path}") from e
|
||||
|
||||
def save(self, path: Path | str) -> Self:
|
||||
if isinstance(path, str):
|
||||
path = Path(path)
|
||||
try:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open("w") as f:
|
||||
f.write(Config.schema().dumps(self))
|
||||
except Exception as e:
|
||||
raise PermissionError(f"Failed to save config file: {path}") from e
|
||||
return self
|
||||
|
||||
|
||||
def init_settings() -> Config:
|
||||
if (Path(__file__).parent / "config.json").exists():
|
||||
return Config.load(Path(__file__).parent / "config.json")
|
||||
# TODO: 读取环境变量
|
||||
return Config().save(Path(__file__).parent / "config.json")
|
||||
|
||||
|
||||
settings = init_settings()
|
||||
Reference in New Issue
Block a user