diff --git a/app/.env.example b/app/.env.example index ebc502b..f0ee9f5 100644 --- a/app/.env.example +++ b/app/.env.example @@ -1,3 +1,4 @@ DJANGO_DEBUG=yes DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/moretech -CELERY_BROKER_URL=redis://localhost:6379/0 \ No newline at end of file +CELERY_BROKER_URL=redis://localhost:6379/0 +MAIN_WALLET=46d3684932f300a7fcdc8cc73cfa3057b5f61695c6e0299a5cb551f645e4cb9c \ No newline at end of file diff --git a/app/conf/settings/base.py b/app/conf/settings/base.py index 65edef0..90623a9 100644 --- a/app/conf/settings/base.py +++ b/app/conf/settings/base.py @@ -216,3 +216,7 @@ REST_FRAMEWORK = { # django-cors-headers CORS_ALLOW_ALL_ORIGINS = True + + +MAIN_WALLET = env("MAIN_WALLET") +TELEGRAM_API = "https://tender-badgers-eat-178-71-165-37.loca.lt" diff --git a/app/users/api/serializers.py b/app/users/api/serializers.py index 5cc984d..3cf17e0 100644 --- a/app/users/api/serializers.py +++ b/app/users/api/serializers.py @@ -1,5 +1,5 @@ from rest_framework import serializers -from ..service import create_season +from ..services import create_season from users.models import User from users.models import User, Department, Stream, Command diff --git a/app/users/service.py b/app/users/services.py similarity index 58% rename from app/users/service.py rename to app/users/services.py index 082b561..22b85fa 100644 --- a/app/users/service.py +++ b/app/users/services.py @@ -1,4 +1,7 @@ from random import shuffle + +from django.conf import settings + from .models import Clan, User from utils.blockchain import transfer_rubbles import requests as r @@ -10,41 +13,36 @@ def end_season(): mx_clan = None for clan in Clan.objects.all(): if sum(map(lambda user: user.respect, clan.user_set.all())) > mx_value: - mx_value = sum(map(lambda user: user.respect, clan.user_set)) + mx_value = sum(map(lambda user: user.respect, clan.user_set.all())) mx_clan = clan for user in mx_clan.user_set.all(): - transfer_rubbles("46d3684932f300a7fcdc8cc73cfa3057b5f61695c6e0299a5cb551f645e4cb9c", user.wallet_public_key, 100) + transfer_rubbles( + settings.MAIN_WALLET, + user.wallet_public_key, + 100, + ) Clan.objects.all().delete() def create_chat(clan: Clan): - user_list = list( - map(lambda user: user.telegram, clan.user_set.all()) - ) + user_list = list(map(lambda user: user.telegram, clan.user_set.all())) if len(user_list): - r.post('https://tender-badgers-eat-178-71-165-37.loca.lt/create-chat', data=json.dumps( - { - 'chat_name': clan.name, - 'users': user_list - } - ), - headers={ - 'accept': 'application/json', - 'Content-Type': 'application/json' - } + r.post( + f"{settings.TELEGRAM_API}/create-chat", + data=json.dumps({"chat_name": clan.name, "users": user_list}), + headers={"accept": "application/json", "Content-Type": "application/json"}, ) def create_season(): if len(Clan.objects.all()): end_season() - + users = list(User.objects.all()) shuffle(users) clan = None for index, user in enumerate(users): - print(index, len(users)) - if (index % 10 == 0) or (index == len(users)-1): + if (index % 10 == 0) or (index == len(users) - 1): if clan is not None: create_chat(clan) clan = Clan.objects.create() @@ -52,5 +50,3 @@ def create_season(): user.save() if len(users) % 10 != 0: create_chat(clan) - - \ No newline at end of file