mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Adds management command for populating suggestions
This commit is contained in:
parent
5174260351
commit
98e537280e
4 changed files with 65 additions and 8 deletions
|
@ -1,12 +1,6 @@
|
||||||
""" Re-create user streams """
|
""" Re-create user streams """
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
import redis
|
from bookwyrm import activitystreams, models
|
||||||
|
|
||||||
from bookwyrm import activitystreams, models, settings
|
|
||||||
|
|
||||||
r = redis.Redis(
|
|
||||||
host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, db=0
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def populate_streams():
|
def populate_streams():
|
||||||
|
|
25
bookwyrm/management/commands/populate_suggestions.py
Normal file
25
bookwyrm/management/commands/populate_suggestions.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
""" Populate suggested users """
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
|
from bookwyrm import models
|
||||||
|
from bookwyrm.suggested_users import rerank_suggestions_task
|
||||||
|
|
||||||
|
|
||||||
|
def populate_suggestions():
|
||||||
|
"""build all the streams for all the users"""
|
||||||
|
users = models.User.objects.filter(
|
||||||
|
local=True,
|
||||||
|
is_active=True,
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
for user in users:
|
||||||
|
rerank_suggestions_task.delay(user)
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""start all over with user suggestions"""
|
||||||
|
|
||||||
|
help = "Populate suggested users for all users"
|
||||||
|
# pylint: disable=no-self-use,unused-argument
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
"""run builder"""
|
||||||
|
populate_suggestions()
|
35
bookwyrm/management/commands/ratings_bot.py
Normal file
35
bookwyrm/management/commands/ratings_bot.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
""" we have the goodreads ratings......... """
|
||||||
|
from datetime import datetime
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
from django.utils import timezone
|
||||||
|
from bookwyrm import models
|
||||||
|
|
||||||
|
|
||||||
|
def get_ratings():
|
||||||
|
"""find and set ratings based on goodreads import lines"""
|
||||||
|
import_items = models.ImportItem.objects.filter(book__isnull=False).all()
|
||||||
|
user = models.User.objects.get(localname="goodreads-average-ratings")
|
||||||
|
for item in import_items:
|
||||||
|
rating = item.data.get("Average Rating")
|
||||||
|
if (
|
||||||
|
not rating
|
||||||
|
or models.ReviewRating.objects.filter(user=user, book=item.book).exists()
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
models.ReviewRating.objects.create(
|
||||||
|
user=user,
|
||||||
|
rating=float(rating),
|
||||||
|
book=item.book.edition,
|
||||||
|
published_date=timezone.make_aware(datetime(2000, 1, 1)), # long ago
|
||||||
|
privacy="followers",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
"""dedplucate allllll the book data models"""
|
||||||
|
|
||||||
|
help = "merges duplicate book data"
|
||||||
|
# pylint: disable=no-self-use,unused-argument
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
"""run deudplications"""
|
||||||
|
get_ratings()
|
5
bw-dev
5
bw-dev
|
@ -107,7 +107,10 @@ case "$CMD" in
|
||||||
populate_streams)
|
populate_streams)
|
||||||
runweb python manage.py populate_streams
|
runweb python manage.py populate_streams
|
||||||
;;
|
;;
|
||||||
|
populate_suggestions)
|
||||||
|
runweb python manage.py populate_suggestions
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unrecognised command. Try: build, clean, up, initdb, resetdb, makemigrations, migrate, bash, shell, dbshell, restart_celery, test, pytest, test_report, black, populate_feeds"
|
echo "Unrecognised command. Try: build, clean, up, initdb, resetdb, makemigrations, migrate, bash, shell, dbshell, restart_celery, test, pytest, test_report, black, populate_streams, populate_suggestions"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue