From 0a2fcddffc5b4b32ed772e02dd69afbe9734b0b1 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Fri, 28 Jul 2023 22:32:10 -0700 Subject: feat(anilist): allow media increment --- src/due/__init__.py | 3 ++- src/due/html/anime.py | 2 +- src/due/html/manga.py | 2 +- src/due/routes/anilist.py | 27 +++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 src/due/routes/anilist.py (limited to 'src') 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'
  • {title} {progress}{total_html} [{available}]
  • ' + f'
  • {title} {progress}{total_html} + [{available}]
  • ' ) 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'
  • {manga["title"]["english"] or manga["title"]["romaji"] or title} {progress} [{available_link}]
  • ' + f'
  • {manga["title"]["english"] or manga["title"]["romaji"] or title} {progress} + [{available_link}]
  • ' ) 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__) + + +@bp.route("/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 "/") -- cgit v1.2.3