<commit_before><commit_msg>Add a management command to generate hashes for all streams that need them.<commit_after>#!/usr/bin/python

from django.core.management.base import BaseCommand

from zerver.lib.utils import generate_random_token
from zerver.models import Stream

class Command(BaseCommand):
    help = """Set a token for all streams that don't have one."""

    def handle(self, **options):
        streams_needing_tokens = Stream.objects.filter(email_token=None)
        for stream in streams_needing_tokens:
            stream.email_token = generate_random_token(32)
            stream.save()
{'fraction_non_alphanumeric': 0.08278145695364239, 'fraction_numerical': 0.0033112582781456954, 'mean_word_length': 4.041666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4550439', 'n_tokens_mistral': 168, 'n_tokens_neox': 162, 'n_words': 50}