from rest_framework_api_key.models import APIKey from webservice_running.handlers.config import BOTLIST def create_webservice_seed(): create_api_key_for_handlers() def create_api_key_for_handlers(): api_key_list = [] for botname in BOTLIST: keys_to_revoke = APIKey.objects.filter(name="botname", revoked=False) # Отзываем каждый ключ for key in keys_to_revoke: key.revoked = True key.save() api_key, key = APIKey.objects.create_key(name=botname) api_key_list.append([botname, key]) print(f"Initial API Key for {botname} handler created.") api_key_list = list(map(lambda x: x[0] + '_key=' + x[1], api_key_list)) txt = '\n'.join(api_key_list) with open('webservice_running/handlers/.env', 'w') as f: f.write(txt)