aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-07-27 11:21:26 -0700
committerFuwn <[email protected]>2023-07-27 11:21:26 -0700
commita32b29a76d8b578df4c373b3c82f8865a98f731f (patch)
treebbd44acfd4da1c07ea192620c37f6b5a3641bcc5 /src
parentfeat(index): log user (diff)
downloadold.due.moe-a32b29a76d8b578df4c373b3c82f8865a98f731f.tar.xz
old.due.moe-a32b29a76d8b578df4c373b3c82f8865a98f731f.zip
feat(index): warn about activity streaks
Diffstat (limited to 'src')
-rw-r--r--src/due/media.py17
-rw-r--r--src/due/routes/index.py7
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"""<a href="/auth/logout">Logout from AniList ({name})</a>
-
- <br>""",
+ {"<p></p><p>You don't have any new activity statuses from the past day! Create one to keep your streak!</p>" if datetime.datetime.fromtimestamp(last_activity(user_name_to_id(name))).date()
+ != datetime.date.today() else "<p></p>"}""",
f"""<a href=\"/?toggle_missing{'&show_manga' if request.args.get('show_manga') is not None else ''}\">{'Show' if request.cookies.get('show_missing') else 'Hide'} unresolved</a><p></p><details open>
<summary>Anime [{anime_length}] <small style="opacity: 50%">{round(anime_time, 2)}s</small></summary>
{anime_html}