Adds management command for populating suggestions

This commit is contained in:
Mouse Reeve 2021-05-22 16:10:11 -07:00
parent 5174260351
commit 98e537280e
4 changed files with 65 additions and 8 deletions

View file

@ -1,12 +1,6 @@
""" Re-create user streams """
from django.core.management.base import BaseCommand
import redis
from bookwyrm import activitystreams, models, settings
r = redis.Redis(
host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, db=0
)
from bookwyrm import activitystreams, models
def populate_streams():

View 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()

View 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
View file

@ -107,7 +107,10 @@ case "$CMD" in
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