diff options
| author | Fuwn <[email protected]> | 2023-07-28 22:32:10 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-07-28 22:32:10 -0700 |
| commit | 0a2fcddffc5b4b32ed772e02dd69afbe9734b0b1 (patch) | |
| tree | 6a8621b20b75acf9d9b5971dd10ea3e9d13ea81a /src | |
| parent | refactor(manga): move rerequests to function (diff) | |
| download | old.due.moe-0a2fcddffc5b4b32ed772e02dd69afbe9734b0b1.tar.xz old.due.moe-0a2fcddffc5b4b32ed772e02dd69afbe9734b0b1.zip | |
feat(anilist): allow media increment
Diffstat (limited to 'src')
| -rw-r--r-- | src/due/__init__.py | 3 | ||||
| -rw-r--r-- | src/due/html/anime.py | 2 | ||||
| -rw-r--r-- | src/due/html/manga.py | 2 | ||||
| -rw-r--r-- | src/due/routes/anilist.py | 27 |
4 files changed, 31 insertions, 3 deletions
diff --git a/src/due/__init__.py b/src/due/__init__.py index 863a817..3cbe721 100644 --- a/src/due/__init__.py +++ b/src/due/__init__.py @@ -1,5 +1,5 @@ from flask import Flask -from due.routes import auth, oauth, index +from due.routes import auth, oauth, index, anilist from due.html.utilities import page from flask_cors import CORS from dotenv import load_dotenv @@ -18,6 +18,7 @@ log.setLevel(logging.ERROR) app.register_blueprint(auth.bp, url_prefix="/auth") app.register_blueprint(oauth.bp, url_prefix="/oauth") app.register_blueprint(index.bp) +app.register_blueprint(anilist.bp, url_prefix="/anilist") app.secret_key = os.getenv("SECRET_KEY") diff --git a/src/due/html/anime.py b/src/due/html/anime.py index 1113965..dfbd741 100644 --- a/src/due/html/anime.py +++ b/src/due/html/anime.py @@ -40,7 +40,7 @@ def anime_to_html(releasing_outdated_anime): ) current_html.append( - f'<li><a href="https://anilist.co/anime/{id}" target="_blank">{title}</a> {progress}{total_html} [{available}]</li>' + f'<li><a href="https://anilist.co/anime/{id}" target="_blank">{title}</a> {progress}{total_html} <a href="/anilist/increment?id={id}&progress={progress + 1}">+</a> [{available}]</li>' ) current_html = sorted(current_html, key=seen) diff --git a/src/due/html/manga.py b/src/due/html/manga.py index dcf6aad..ea655ba 100644 --- a/src/due/html/manga.py +++ b/src/due/html/manga.py @@ -153,7 +153,7 @@ def manga_to_html(releasing_outdated_manga, show_missing): ) current_html.append( - f'<li><a href="https://anilist.co/manga/{id}" target="_blank">{manga["title"]["english"] or manga["title"]["romaji"] or title}</a> {progress} [{available_link}]</li>' + f'<li><a href="https://anilist.co/manga/{id}" target="_blank">{manga["title"]["english"] or manga["title"]["romaji"] or title}</a> {progress} <a href="/anilist/increment?id={id}&progress={progress + 1}">+</a> [{available_link}]</li>' ) joblib.Parallel(n_jobs=int(os.getenv("CONCURRENT_JOBS")) or 4, require="sharedmem")( diff --git a/src/due/routes/anilist.py b/src/due/routes/anilist.py new file mode 100644 index 0000000..63e1f7d --- /dev/null +++ b/src/due/routes/anilist.py @@ -0,0 +1,27 @@ +from flask import redirect, Blueprint, request +import requests +import json + +bp = Blueprint("anilist", __name__) + + [email protected]("/increment") +def increment_media(): + if request.cookies.get("anilist"): + anilist = json.loads(request.cookies.get("anilist")) + + return requests.post( + "https://graphql.anilist.co", + json={ + "query": f"""mutation {{ SaveMediaListEntry(mediaId: {request.args.get('id') or 30013}, progress: {request.args.get('progress') or 1}) {{ + id + }} }}""" + }, + headers={ + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": anilist["token_type"] + " " + anilist["access_token"], + }, + ).json() + + return redirect(request.headers.get("Referer") or "/") |