aboutsummaryrefslogtreecommitdiff
path: root/watch/utils.py
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-08-30 20:30:04 -0400
committerBobby <[email protected]>2024-08-30 20:30:04 -0400
commit2ac4f44fc18c06df94f6afff8f775e7ee5de5308 (patch)
tree23ea5002bf983a780902e8ca48d0bfa712fdab40 /watch/utils.py
parent0d6aacd2ab38f0d91181b7880e896e2b98d18871 (diff)
downloadyugen-2ac4f44fc18c06df94f6afff8f775e7ee5de5308.tar.xz
yugen-2ac4f44fc18c06df94f6afff8f775e7ee5de5308.zip
watch history update + some general stuff
Diffstat (limited to 'watch/utils.py')
-rw-r--r--watch/utils.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/watch/utils.py b/watch/utils.py
index 83888f6..857601a 100644
--- a/watch/utils.py
+++ b/watch/utils.py
@@ -1,6 +1,7 @@
import redis
import os
import dotenv
+from user_profile.models import UserHistory
dotenv.load_dotenv()
@@ -11,6 +12,17 @@ r = redis.Redis(
ssl=True,
)
+def update_anime_user_history(user, anime_id, episode, time_watched):
+ # per episode history
+ history, created = UserHistory.objects.get_or_create(user=user, anime_id=anime_id, episode=episode)
+ history.time_watched = time_watched
+ history.save()
+
+def get_anime_user_history(user, anime_id):
+ history = UserHistory.objects.filter(user=user, anime_id=anime_id).order_by("-episode")
+ return history
+
+
def store_in_redis_cache(anime_id, data):
r.set(anime_id, data, ex=60*60*24*30) # 30 days
print("data cached", anime_id)