fixed end season, moved secrets

This commit is contained in:
Alexander Karpov 2022-10-08 20:13:21 +03:00
parent ae7cfe5166
commit 8beee17e31
4 changed files with 23 additions and 22 deletions

View File

@ -1,3 +1,4 @@
DJANGO_DEBUG=yes DJANGO_DEBUG=yes
DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/moretech DATABASE_URL=postgres://postgres:debug@127.0.0.1:5432/moretech
CELERY_BROKER_URL=redis://localhost:6379/0 CELERY_BROKER_URL=redis://localhost:6379/0
MAIN_WALLET=46d3684932f300a7fcdc8cc73cfa3057b5f61695c6e0299a5cb551f645e4cb9c

View File

@ -216,3 +216,7 @@ REST_FRAMEWORK = {
# django-cors-headers # django-cors-headers
CORS_ALLOW_ALL_ORIGINS = True CORS_ALLOW_ALL_ORIGINS = True
MAIN_WALLET = env("MAIN_WALLET")
TELEGRAM_API = "https://tender-badgers-eat-178-71-165-37.loca.lt"

View File

@ -1,5 +1,5 @@
from rest_framework import serializers 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
from users.models import User, Department, Stream, Command from users.models import User, Department, Stream, Command

View File

@ -1,4 +1,7 @@
from random import shuffle from random import shuffle
from django.conf import settings
from .models import Clan, User from .models import Clan, User
from utils.blockchain import transfer_rubbles from utils.blockchain import transfer_rubbles
import requests as r import requests as r
@ -10,28 +13,24 @@ def end_season():
mx_clan = None mx_clan = None
for clan in Clan.objects.all(): for clan in Clan.objects.all():
if sum(map(lambda user: user.respect, clan.user_set.all())) > mx_value: 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 mx_clan = clan
for user in mx_clan.user_set.all(): 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() Clan.objects.all().delete()
def create_chat(clan: Clan): def create_chat(clan: Clan):
user_list = list( user_list = list(map(lambda user: user.telegram, clan.user_set.all()))
map(lambda user: user.telegram, clan.user_set.all())
)
if len(user_list): if len(user_list):
r.post('https://tender-badgers-eat-178-71-165-37.loca.lt/create-chat', data=json.dumps( r.post(
{ f"{settings.TELEGRAM_API}/create-chat",
'chat_name': clan.name, data=json.dumps({"chat_name": clan.name, "users": user_list}),
'users': user_list headers={"accept": "application/json", "Content-Type": "application/json"},
}
),
headers={
'accept': 'application/json',
'Content-Type': 'application/json'
}
) )
@ -43,8 +42,7 @@ def create_season():
shuffle(users) shuffle(users)
clan = None clan = None
for index, user in enumerate(users): 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: if clan is not None:
create_chat(clan) create_chat(clan)
clan = Clan.objects.create() clan = Clan.objects.create()
@ -52,5 +50,3 @@ def create_season():
user.save() user.save()
if len(users) % 10 != 0: if len(users) % 10 != 0:
create_chat(clan) create_chat(clan)