1 Commits

Author SHA1 Message Date
355a2b9acf Add renovate.json 2025-11-27 17:32:53 +00:00
10 changed files with 104 additions and 245 deletions

View File

@@ -1,5 +1,5 @@
[tool.bumpversion]
current_version = "0.1.2"
current_version = "0.1.1"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)"
serialize = ["{major}.{minor}.{patch}"]
search = "{current_version}"

View File

@@ -1,103 +0,0 @@
{
"categories": [
{
"title": "## 🚀 Features",
"labels": [
"add",
"Add",
"Kind/Feature",
"feat",
"Feature",
"Feat"
]
},
{
"title": "## 🧰 Enhancements",
"labels": [
"enhancement",
"Enhancement",
"Kind/Enhancement",
"improvement",
"Improvement",
"Kind/Improvement"
]
},
{
"title": "## 🐛 Fixes",
"labels": [
"fix",
"Fix",
"Kind/Bug",
"Kind/Security"
]
},
{
"title": "## 🧪 Upgrade",
"labels": ["upgrade","Upgrade","Clean"]
}
,
{
"title": "## 📝 Documentation",
"labels": ["docs","Docs", "Kind/Documentation"]
},
{
"title": "## 🛠️ Maintenance",
"labels": [
"maintenance",
"Maintenance",
"Kind/Maintenance",
"chore",
"Chore",
"Kind/Chore"
]
},
{
"title": "## ⏪ Reverts",
"labels": [
"revert",
"Revert",
"Kind/Revert",
"Kind/Reverts",
"reverts",
"Reverts"
]
},
{
"title": "## 🗑️ Deprecation",
"labels": ["deprecation","Deprecation", "Kind/Deprecation"]
},
{
"title": "## ⚡️ Performance Improvements",
"labels": [
"perf",
"Perf",
"Kind/Performance"
]
},
{
"title": "## 🎨 Styling",
"labels": [
"style",
"Style",
"Kind/Style"
]
},
{
"title": "## 🎯 Other Changes",
"labels": []
}
],
"label_extractor": [
{
"pattern": "(\\w+) (.+)",
"target": "$1",
"on_property": "title"
}
],
"sort": "ASC",
"template": "${{CHANGELOG}}",
"pr_template": "- ${{TITLE}}\n - PR: #${{NUMBER}}",
"empty_template": "- no changes",
"max_pull_requests": 1000,
"max_back_track_time_days": 1000
}

View File

@@ -1,83 +1,80 @@
on:
workflow_dispatch:
inputs:
release_notes:
description: Release notes (use \n for newlines)
type: string
required: false
github_release:
description: "Create Gitea Release"
description: 'Create Gitea Release'
default: true
type: boolean
bump:
description: "Bump type"
description: 'Bump type'
required: true
default: "patch"
default: 'patch'
type: choice
options:
- "major"
- "minor"
- "patch"
- 'major'
- 'minor'
- 'patch'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@master
with:
fetch-depth: 0
fetch-tags: true
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python
run: uv python install
with:
python-version-file: "pyproject.toml"
- name: Set Git identity
run: |
git config user.name "Gitea CI"
git config user.email "ci@git.theprivateserver.de"
- name: Bump version
id: bump
run: |
uv tool install bump-my-version
uv tool run bump-my-version bump ${{ github.event.inputs.bump }}
# echo the version to github env, the version is shown by using uv tool run bump-my-version show current_version
echo "VERSION<<EOF" >> $GITHUB_ENV
echo "$(uv tool run bump-my-version show current_version)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Build Changelog
id: build_changelog
uses: https://github.com/mikepenz/release-changelog-builder-action@v5
with:
platform: "gitea"
baseURL: "http://192.168.178.110:3000"
configuration: ".gitea/changelog_config.json"
- name: Checkout code
uses: actions/checkout@master
- name: Install uv
uses: astral-sh/setup-uv@v5
- name: Set up Python
run: uv python install
- name: Set Git identity
run: |
git config user.name "Gitea CI"
git config user.email "ci@git.theprivateserver.de"
- name: Bump version
id: bump
run: |
uv tool install bump-my-version
uv tool run bump-my-version bump ${{ github.event.inputs.bump }}
# echo the version to github env, the version is shown by using uv tool run bump-my-version show current_version
echo "VERSION<<EOF" >> $GITHUB_ENV
echo "$(uv tool run bump-my-version show current_version)" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Create release notes
run: |
mkdir release_notes
echo -e "${{ inputs.release_notes }}" >> release_notes/release_notes.md
echo "Release notes:"
cat release_notes/release_notes.md
echo ""
- name: Build package
run: uv build
- name: Publish package
env:
USERNAME: ${{ github.repository_owner }}
run: uv publish --publish-url https://git.theprivateserver.de/api/packages/$USERNAME/pypi/ -t ${{ secrets.TOKEN }}
env:
GITHUB_TOKEN: ${{ secrets.GITEA_TOKEN }}
- name: Build package
run: uv build
- name: Publish package
env:
USERNAME: ${{ github.repository_owner }}
run: uv publish --publish-url https://git.theprivateserver.de/api/packages/$USERNAME/pypi/ -t ${{ secrets.TOKEN }}
- name: Create release
uses: softprops/action-gh-release@master
id: create_release
if: ${{ github.event.inputs.github_release == 'true' }}
with:
tag_name: v${{ env.VERSION }}
release_name: Release v${{ env.VERSION }}
body: ${{steps.build_changelog.outputs.changelog}}
draft: false
prerelease: false
make_latest: true
files: |
dist/*
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
- name: Create release
id: create_release
if: ${{ github.event.inputs.github_release == 'true' }}
uses: softprops/action-gh-release@master
with:
tag_name: ${{ env.VERSION }}
release_name: Release ${{ env.VERSION }}
body_path: release_notes/release_notes.md
draft: false
prerelease: false
make_latest: true
files: |
dist/*
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}

View File

@@ -1,6 +1,6 @@
[project]
name = "anilistapi"
version = "0.1.2"
version = "0.1.1"
description = "Add your description here"
readme = "README.md"
authors = [{ name = "WorldTeacher", email = "coding_contact@pm.me" }]
@@ -12,10 +12,7 @@ requires = ["hatchling"]
build-backend = "hatchling.build"
[dependency-groups]
test = [
"pytest>=8.3.4",
"pytest-cov>=6.2.1",
]
test = ["pytest>=8.3.4"]
[tool.pytest.ini_options]
testpaths = ["tests"]

3
renovate.json Normal file
View File

@@ -0,0 +1,3 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
}

View File

@@ -2,5 +2,4 @@ from importlib.metadata import version
__version__ = version("anilistapi")
__contact__ = "coding_contact@pm.me"
__all__ = ["AnilistAPI", "MediaFormat"]
from .api import AnilistAPI, MediaFormat
from .api import AnilistAPI

View File

@@ -1,37 +1,19 @@
import os
import time
from enum import Enum
import requests
from limit import limit
from anilistapi import __contact__, __version__
from .schemas.manga import Manga, Tag
from .queries.manga import (
GENRES_QUERY,
ID_QUERY,
MANGA_QUERY,
MANGA_ID_QUERY,
REQUESTS_QUERY,
GENRES_QUERY,
TAGS_QUERY,
)
from .schemas.manga import Manga, Tag
from limit import limit
from anilistapi import __version__, __contact__
import os
import time
REQUEST_LIMIT = 1
REQUEST_PERIOD = 1
class MediaFormat(str, Enum):
MANGA = "MANGA"
NOVEL = "NOVEL"
ONE_SHOT = "ONE_SHOT"
TV = "TV"
TV_SHORT = "TV_SHORT"
MOVIE = "MOVIE"
OVA = "OVA"
ONA = "ONA"
MUSIC = "MUSIC"
SPECIAL = "SPECIAL"
# add a function to get
REQUEST_LIMIT = 90
REQUEST_PERIOD = 60
class AnilistAPI:
@@ -43,24 +25,16 @@ class AnilistAPI:
@limit(REQUEST_LIMIT, REQUEST_PERIOD)
def request(self, query: str, variables: dict) -> dict:
url = "https://graphql.anilist.co"
try:
response = requests.post(url, json={"query": query, "variables": variables})
time.sleep(1)
if response.status_code != 200:
return {}
# raise Exception(f"Error: {response}, response: {response.json()}, query: {query}, variables: {variables}")
return response.json()
except:
response = requests.post(url, json={"query": query, "variables": variables})
time.sleep(1)
if response.status_code != 200:
return {}
# raise Exception(f"Error: {response}, response: {response.json()}, query: {query}, variables: {variables}")
return response.json()
def search_manga(self, search: str, format: MediaFormat) -> list[Manga]:
variables = {"search": search, "format": format, "type": "MANGA"}
try:
response = self.request(REQUESTS_QUERY, variables)
except:
time.sleep(15)
return self.search_manga(search, format)
def search_manga(self, search: str) -> list[Manga]:
variables = {"search": search, "format": "MANGA"}
response = self.request(REQUESTS_QUERY, variables)
# check if reponse has data Page and media
if not response.get("data", {}).get("Page", {}).get("media"):
return []
@@ -70,17 +44,15 @@ class AnilistAPI:
return res
def get_manga(self, id: int) -> Manga:
if str(id).isnumeric():
id = int(id)
assert isinstance(id, int), "id must be an integer"
variables = {"id": id}
response = self.request(ID_QUERY, variables)
response = self.request(MANGA_ID_QUERY, variables)
if not response.get("data", {}).get("Media"):
return None
return Manga(**response["data"]["Media"])
def kompage_search(self, search: str, format: MediaFormat) -> list[Manga]:
variables = {"search": search, "format": format, "type": "MANGA"}
def kompage_search(self, search: str) -> list[Manga]:
variables = {"search": search}
response = self.request(REQUESTS_QUERY, variables)
# check if reponse has data Page and media
if not response.get("data", {}).get("Page", {}).get("media"):

View File

@@ -1,5 +1,5 @@
QUERY = """
query media($search: String, $type: MediaType) {
MANGA_QUERY = """
query media($search: String) {
Page {
pageInfo {
hasNextPage
@@ -8,7 +8,7 @@ Page {
currentPage
lastPage
}
media(type: $type, search: $search) {
media(type: MANGA, search: $search) {
id
title {
romaji
@@ -21,9 +21,9 @@ Page {
}
"""
ID_QUERY = """
MANGA_ID_QUERY = """
query media($id: Int) { # Define which variables will be used in the query (id)
Media (id:$id) { # Insert our variables into the query arguments (id)
Media (type: MANGA, id:$id) { # Insert our variables into the query arguments (id)
id
title {
romaji
@@ -53,12 +53,11 @@ Media (id:$id) { # Insert our variables into the query arguments (id)
type
}
countryOfOrigin
siteUrl
}
}
"""
REQUESTS_QUERY = """query query($search: String, $genres:[String], $tags:[String], $format: MediaFormat, $type: MediaType) {
REQUESTS_QUERY = """query query($search: String, $genres:[String], $tags:[String], $format: MediaFormat) {
Page(perPage: 100) {
pageInfo {
hasNextPage
@@ -67,7 +66,7 @@ Page(perPage: 100) {
currentPage
lastPage
}
media(type: $type, search: $search, genre_in: $genres, tag_in: $tags, sort: SEARCH_MATCH, format: $format) {
media(type: MANGA, search: $search, genre_in: $genres, tag_in: $tags, sort: SEARCH_MATCH, format: $format) {
id
title {
romaji
@@ -103,8 +102,8 @@ Page(perPage: 100) {
}
}"""
REQUESTED_QUERY = """query query($search: Int, $type: MediaType) {
Media(type: $type, id: $search, sort: SEARCH_MATCH) {
REQUESTED_QUERY = """query query($search: Int) {
Media(type: MANGA, id: $search, sort: SEARCH_MATCH) {
id
title {
romaji

View File

@@ -44,7 +44,3 @@ class Manga:
@property
def isLightNovel(self):
return self.format == "NOVEL"
@property
def name(self):
return self.title.__repr__()

View File

@@ -8,11 +8,10 @@ class Title:
native: str = None
def __repr__(self):
return self.english if self.english else self.romaji if self.romaji else self.native
return self.english if self.english else self.native
def __str__(self):
return self.english if self.english else self.romaji if self.romaji else self.native
return self.english if self.english else self.native
@property
def alternateTitles(self):