api: Format code
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
# ruff: noqa: F401
|
# ruff: noqa: F401
|
||||||
|
|
||||||
from .create_book import (
|
from .create_book import (
|
||||||
fetch_story,
|
|
||||||
fetch_story_from_partId,
|
|
||||||
fetch_story_content_zip,
|
|
||||||
fetch_cookies,
|
fetch_cookies,
|
||||||
|
fetch_story,
|
||||||
|
fetch_story_content_zip,
|
||||||
|
fetch_story_from_partId,
|
||||||
)
|
)
|
||||||
from .generators import PDFGenerator, EPUBGenerator
|
from .exceptions import PartNotFoundError, StoryNotFoundError, WattpadError
|
||||||
from .exceptions import WattpadError, StoryNotFoundError, PartNotFoundError
|
from .generators import EPUBGenerator, PDFGenerator
|
||||||
from .utils import generate_clean_part_html, slugify
|
|
||||||
from .logs import logger
|
from .logs import logger
|
||||||
from .parser import fetch_image
|
from .parser import fetch_image
|
||||||
|
from .utils import generate_clean_part_html, slugify
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pydantic import model_validator, field_validator
|
|
||||||
|
from pydantic import field_validator, model_validator
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,18 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Optional, Tuple
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
import backoff
|
import backoff
|
||||||
from pydantic import TypeAdapter
|
|
||||||
from .logs import logger
|
|
||||||
from eliot import start_action
|
|
||||||
from aiohttp import ClientResponseError
|
from aiohttp import ClientResponseError
|
||||||
from aiohttp_client_cache.session import CachedSession
|
from aiohttp_client_cache.session import CachedSession
|
||||||
from .models import Story
|
from eliot import start_action
|
||||||
|
from pydantic import TypeAdapter
|
||||||
|
|
||||||
from .exceptions import PartNotFoundError, StoryNotFoundError
|
from .exceptions import PartNotFoundError, StoryNotFoundError
|
||||||
from .vars import headers, cache
|
from .logs import logger
|
||||||
|
from .models import Story
|
||||||
|
from .vars import cache, headers
|
||||||
|
|
||||||
story_ta = TypeAdapter(Story)
|
story_ta = TypeAdapter(Story)
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ class StoryNotFoundError(WattpadError):
|
|||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class PartNotFoundError(StoryNotFoundError): ...
|
class PartNotFoundError(StoryNotFoundError):
|
||||||
|
...
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
from ebooklib import epub
|
|
||||||
from typing import List
|
|
||||||
from ..models import Story
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from typing import List
|
||||||
|
|
||||||
import bs4
|
import bs4
|
||||||
from aiohttp_client_cache.session import CachedSession
|
from aiohttp_client_cache.session import CachedSession
|
||||||
|
from ebooklib import epub
|
||||||
|
|
||||||
|
from ..models import Story
|
||||||
|
|
||||||
headers = {}
|
headers = {}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
from typing import List, cast
|
|
||||||
import tempfile
|
import tempfile
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
import bs4
|
|
||||||
from weasyprint import HTML, CSS
|
|
||||||
from weasyprint.text.fonts import FontConfiguration
|
|
||||||
from exiftool import ExifTool
|
|
||||||
from ..logs import exiftool_logger
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from ..utils import smart_trim
|
|
||||||
from ..models import Story
|
|
||||||
from eliot import start_action
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from typing import List, cast
|
||||||
|
|
||||||
|
import bs4
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
from eliot import start_action
|
||||||
|
from exiftool import ExifTool
|
||||||
|
from weasyprint import CSS, HTML
|
||||||
|
from weasyprint.text.fonts import FontConfiguration
|
||||||
|
|
||||||
|
from ..logs import exiftool_logger
|
||||||
|
from ..models import Story
|
||||||
|
from ..utils import smart_trim
|
||||||
|
|
||||||
|
|
||||||
async def fetch_image(*args, **kwargs):
|
async def fetch_image(*args, **kwargs):
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
from eliot import to_file
|
from eliot import to_file
|
||||||
from eliot.stdlib import EliotHandler
|
from eliot.stdlib import EliotHandler
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import TypedDict, Optional, List
|
from typing import List, Optional, TypedDict
|
||||||
|
|
||||||
|
|
||||||
class CopyrightData(TypedDict):
|
class CopyrightData(TypedDict):
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
|
import asyncio
|
||||||
|
from itertools import batched, chain
|
||||||
from typing import List, Tuple
|
from typing import List, Tuple
|
||||||
|
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from bs4 import BeautifulSoup, Tag
|
from bs4 import BeautifulSoup, Tag
|
||||||
from itertools import batched, chain
|
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from .vars import headers
|
|
||||||
from eliot import start_action
|
from eliot import start_action
|
||||||
|
|
||||||
|
from .vars import headers
|
||||||
|
|
||||||
|
|
||||||
def clean_tree(title: str, id: int, body: str) -> BeautifulSoup:
|
def clean_tree(title: str, id: int, body: str) -> BeautifulSoup:
|
||||||
original_soup = BeautifulSoup(body)
|
original_soup = BeautifulSoup(body)
|
||||||
new_soup = BeautifulSoup("""
|
new_soup = BeautifulSoup(
|
||||||
|
"""
|
||||||
<h1 class="chapter-name" id={id}>{title}</h1>
|
<h1 class="chapter-name" id={id}>{title}</h1>
|
||||||
<section class="chapter-body"></section>
|
<section class="chapter-body"></section>
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
insert_at = new_soup.find("section")
|
insert_at = new_soup.find("section")
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import re
|
import re
|
||||||
import bs4
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
|
import bs4
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
from .models import Part
|
from .models import Part
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from .config import Config, CacheTypes
|
|
||||||
from aiohttp_client_cache import FileBackend, RedisBackend
|
from aiohttp_client_cache import FileBackend, RedisBackend
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
from .config import CacheTypes, Config
|
||||||
from .logs import logger
|
from .logs import logger
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
|
|||||||
+12
-11
@@ -1,12 +1,13 @@
|
|||||||
"""WattpadDownloader API Server."""
|
"""WattpadDownloader API Server."""
|
||||||
|
|
||||||
from typing import Optional
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from pathlib import Path
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
from eliot import start_action
|
|
||||||
from aiohttp import ClientResponseError
|
from aiohttp import ClientResponseError
|
||||||
|
from eliot import start_action
|
||||||
from fastapi import FastAPI, Request
|
from fastapi import FastAPI, Request
|
||||||
from fastapi.responses import (
|
from fastapi.responses import (
|
||||||
FileResponse,
|
FileResponse,
|
||||||
@@ -15,21 +16,21 @@ from fastapi.responses import (
|
|||||||
StreamingResponse,
|
StreamingResponse,
|
||||||
)
|
)
|
||||||
from fastapi.staticfiles import StaticFiles
|
from fastapi.staticfiles import StaticFiles
|
||||||
|
|
||||||
from create_book import (
|
from create_book import (
|
||||||
EPUBGenerator,
|
EPUBGenerator,
|
||||||
fetch_story,
|
|
||||||
fetch_story_from_partId,
|
|
||||||
fetch_story_content_zip,
|
|
||||||
fetch_image,
|
|
||||||
fetch_cookies,
|
|
||||||
WattpadError,
|
|
||||||
StoryNotFoundError,
|
StoryNotFoundError,
|
||||||
|
WattpadError,
|
||||||
|
fetch_cookies,
|
||||||
|
fetch_image,
|
||||||
|
fetch_story,
|
||||||
|
fetch_story_content_zip,
|
||||||
|
fetch_story_from_partId,
|
||||||
generate_clean_part_html,
|
generate_clean_part_html,
|
||||||
slugify,
|
|
||||||
logger,
|
logger,
|
||||||
|
slugify,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
BUILD_PATH = Path(__file__).parent / "build"
|
BUILD_PATH = Path(__file__).parent / "build"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user