From a32b29a76d8b578df4c373b3c82f8865a98f731f Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 27 Jul 2023 11:21:26 -0700 Subject: feat(index): warn about activity streaks --- src/due/media.py | 17 +++++++++++++++++ src/due/routes/index.py | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/due/media.py b/src/due/media.py index 5dde303..8c86855 100644 --- a/src/due/media.py +++ b/src/due/media.py @@ -15,6 +15,23 @@ def user_id(anilist): ) +def last_activity(id): + return int( + requests.post( + "https://graphql.anilist.co", + json={ + "query": f"""{{ Activity(userId: {id}, type: MEDIA_LIST, sort: ID_DESC) {{ + __typename ... on ListActivity {{ createdAt }} + }} }}""" + }, + headers={ + "Content-Type": "application/json", + "Accept": "application/json", + }, + ).json()["data"]["Activity"]["createdAt"] + ) + + def user_name_to_id(name): return int( requests.post( diff --git a/src/due/routes/index.py b/src/due/routes/index.py index cb1baab..ce8d66c 100644 --- a/src/due/routes/index.py +++ b/src/due/routes/index.py @@ -1,9 +1,10 @@ import time from due.html import anime_to_html, manga_to_html, page -from due.media import create_collection +from due.media import create_collection, last_activity, user_name_to_id from flask import make_response, redirect, request, Blueprint import json import os +import datetime bp = Blueprint("index", __name__) @@ -109,8 +110,8 @@ def home(): response.set_data( page( f"""Logout from AniList ({name}) - -
""", + {"

You don't have any new activity statuses from the past day! Create one to keep your streak!

" if datetime.datetime.fromtimestamp(last_activity(user_name_to_id(name))).date() + != datetime.date.today() else "

"}""", f"""{'Show' if request.cookies.get('show_missing') else 'Hide'} unresolved

Anime [{anime_length}] {round(anime_time, 2)}s {anime_html} -- cgit v1.2.3