diff --git a/bookwyrm/management/commands/populate_streams.py b/bookwyrm/management/commands/populate_streams.py index 04f6bf6e2..f8aa21a52 100644 --- a/bookwyrm/management/commands/populate_streams.py +++ b/bookwyrm/management/commands/populate_streams.py @@ -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(): diff --git a/bookwyrm/management/commands/populate_suggestions.py b/bookwyrm/management/commands/populate_suggestions.py new file mode 100644 index 000000000..32495497e --- /dev/null +++ b/bookwyrm/management/commands/populate_suggestions.py @@ -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() diff --git a/bookwyrm/management/commands/ratings_bot.py b/bookwyrm/management/commands/ratings_bot.py new file mode 100644 index 000000000..57cd84999 --- /dev/null +++ b/bookwyrm/management/commands/ratings_bot.py @@ -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() diff --git a/bw-dev b/bw-dev index c2b63bc17..0b583083c 100755 --- a/bw-dev +++ b/bw-dev @@ -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