Skip to content

Commit

Permalink
Ajout d'une commande pour la migration de Gravatar à jdenticon
Browse files Browse the repository at this point in the history
  • Loading branch information
Situphen committed Sep 28, 2024
1 parent 21c1f97 commit 14b630d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions zds/utils/management/commands/migrate_from_gravatar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from hashlib import md5

import requests
from django.core.management.base import BaseCommand

from zds.member.models import Profile


class Command(BaseCommand):
help = "Migrate from Gravatar"

def handle(self, *args, **options):
for profile in Profile.objects.select_related("user").filter(avatar_url__isnull=True).iterator():
hash = md5(profile.user.email.lower().encode("utf-8")).hexdigest()
gravatar_url = f"https://secure.gravatar.com/avatar/{hash}"
r = requests.get(f"{gravatar_url}?d=404")
if r.status_code == 200:
profile.avatar_url = f"{gravatar_url}?s=200"
profile.save()
self.stdout.write(self.style.SUCCESS(f"Successfully migrated from Gravatar!"))

0 comments on commit 14b630d

Please sign in to comment.