Skip to content

Commit

Permalink
migrate: use uv to manage project
Browse files Browse the repository at this point in the history
  • Loading branch information
tbdsux committed Jan 3, 2025
1 parent 6f4bc65 commit e92d136
Show file tree
Hide file tree
Showing 17 changed files with 1,384 additions and 91 deletions.
21 changes: 16 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
.vercel
venv
__pycache__/
test.py
# .env
.env
.env.local
.env.production

# rope
.ropeproject

# cache
.mypy_cache
.pytest_cache
.pytest_cache
__pycache__/

# vercel
.vercel

# virtual environments
.venv
venv
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.9
3.12
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"python.analysis.extraPaths": ["venv/lib"],
"python.linting.mypyEnabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
}
}
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

<h4>THIS SERVICE IS ONLY CREATED TO SATISFY THE NEED FOR AN API FOR [MYDRAMALIST.COM](https://mydramalist.com). THIS WILL BE STOPPED ONCE AN OFFICIAL API WILL BE RELEASED.</h4>

### Deploy Your Own

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FTheBoringDude%2Fkuryana)

</div>

## API Use
Expand Down
File renamed without changes.
Empty file added app/handlers/__init__.py
Empty file.
18 changes: 9 additions & 9 deletions api/fetch.py → app/handlers/fetch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Dict, Any, List

from api import MYDRAMALIST_WEBSITE
from api.parser import BaseFetch
import re
from typing import Any, Dict, List
from urllib.parse import urljoin

from bs4 import BeautifulSoup
from urllib.parse import urljoin
import re

from app import MYDRAMALIST_WEBSITE
from app.handlers.parser import BaseFetch


class FetchDrama(BaseFetch):
Expand Down Expand Up @@ -381,9 +381,9 @@ def _parse_total_stats(self, item: BeautifulSoup) -> Dict[str, str]:
movies_stats = item.find("label", class_="mdl-style-movies")
days_stats = item.find("label", class_="mdl-style-days")
return {
label.find("span", class_="name")
.get_text(strip=True): label.find("span", class_="cnt")
.get_text(strip=True)
label.find("span", class_="name").get_text(strip=True): label.find(
"span", class_="cnt"
).get_text(strip=True)
for label in [
drama_stats,
tvshows_stats,
Expand Down
8 changes: 4 additions & 4 deletions api/parser.py → app/handlers/parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Dict, List, Type, TypeVar, Union
from urllib.parse import urljoin

Expand All @@ -7,7 +7,7 @@
from bs4 import BeautifulSoup
from bs4.element import NavigableString, Tag

from api import MYDRAMALIST_WEBSITE
from app import MYDRAMALIST_WEBSITE

T = TypeVar("T", bound="Parser")

Expand Down Expand Up @@ -102,7 +102,7 @@ def search(self) -> Dict[str, Any]:
return {
"query": self.query,
"results": self.search_results,
"scrape_date": datetime.utcnow(),
"scrape_date": datetime.now(timezone.utc),
}


Expand All @@ -120,7 +120,7 @@ def fetch(self) -> Dict[str, Any]:
return {
"slug_query": self.query,
"data": self.info,
"scrape_date": datetime.utcnow(),
"scrape_date": datetime.now(timezone.utc),
}

def _get(self) -> None:
Expand Down
14 changes: 7 additions & 7 deletions api/search.py → app/handlers/search.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Any, Tuple, Union, Optional

from api import MYDRAMALIST_WEBSITE
from api.parser import BaseSearch
from typing import Any, Optional, Tuple, Union
from urllib.parse import urljoin

from bs4 import BeautifulSoup
from bs4.element import Tag, NavigableString, ResultSet
from urllib.parse import urljoin
from bs4.element import NavigableString, ResultSet, Tag

from app import MYDRAMALIST_WEBSITE
from app.handlers.parser import BaseSearch


class Search(BaseSearch):
Expand Down Expand Up @@ -108,7 +108,7 @@ def _get_search_results(self) -> None:

# extract drama title
r["title"] = title.strip()

# drama ranking
r["ranking"] = self._res_get_ranking(result)

Expand Down
10 changes: 4 additions & 6 deletions api/main.py → app/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from typing import Dict, Any

from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware
from typing import Any, Dict

# bypassing cloudflare anti-bot
import cloudscraper
from fastapi import FastAPI, Response
from fastapi.middleware.cors import CORSMiddleware

from api.utils import search_func, fetch_func

from app.utils import fetch_func, search_func

app = FastAPI()

Expand Down
16 changes: 8 additions & 8 deletions api/utils.py → app/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from typing import Dict, Any, Tuple
from typing import Any, Dict, Tuple

from api.search import Search
from api.fetch import (
from app.handlers.fetch import (
FetchCast,
FetchDrama,
FetchDramaList,
FetchList,
FetchPerson,
FetchCast,
FetchReviews,
FetchDramaList,
)
from app.handlers.search import Search


def error(code: int, description: str) -> Dict[str, Any]:
return {
"error": True,
"code": code,
"description": "404 Not Found"
if code == 404
else description, # prioritize error 404
"description": (
"404 Not Found" if code == 404 else description
), # prioritize error 404
}


Expand Down
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[project]
name = "kuryana"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"beautifulsoup4>=4.12.3",
"cloudscraper>=1.2.71",
"fastapi[standard]>=0.115.6",
"lxml>=5.3.0",
]

[dependency-groups]
dev = [
"flake8>=7.1.1",
"mypy>=1.14.1",
"pytest>=8.3.4",
"ruff>=0.8.5",
]
36 changes: 0 additions & 36 deletions requirements.txt

This file was deleted.

4 changes: 3 additions & 1 deletion tests/test_fetch_dramalist.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from api.fetch import FetchDramaList
from pathlib import Path

import pytest
from bs4 import BeautifulSoup

from app.handlers.fetch import FetchDramaList


@pytest.fixture
def sample_obj():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from fastapi.testclient import TestClient

from api.main import app
from app.main import app

client = TestClient(app)

Expand Down
Loading

0 comments on commit e92d136

Please sign in to comment.