Skip to content

Commit

Permalink
Исправлено сравнение текущего и нового статуса
Browse files Browse the repository at this point in the history
  • Loading branch information
Павел Сарыгин committed Feb 6, 2024
1 parent 408f43f commit 28c1255
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion short_tracker/api/v1/bot/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.auth import get_user_model
from rest_framework.generics import ListAPIView
from rest_framework.generics import ListAPIView, GenericAPIView
from rest_framework.views import APIView

from .serializer import BotSerializer

Expand Down
11 changes: 8 additions & 3 deletions short_tracker_bot/short_tracker_bot/handlers/hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ async def get_token(state, bot):


async def get_messages(data, chat_id, bot: Bot):
logging.info('Вход в функцию получения сообщений')
for msg in data['results'][0]['messages']:
if not get_data_from_redis(f'{chat_id}_msg_{msg["id"]}'):
logging.info(msg)
message_in_redis = get_data_from_redis(f'{chat_id}_msg_{msg["id"]}')
logging.info(message_in_redis)
if not message_in_redis:
await save_data_to_redis(
f'{chat_id}_msg_{msg["id"]}', msg['message_body']
)
Expand All @@ -62,7 +66,8 @@ async def get_messages(data, chat_id, bot: Bot):
text=f'У вас новое сообщение\n\"{msg["message_body"]}\"'
)
for reply in msg['reply']:
if not get_data_from_redis(f'{chat_id}_reply_{msg["id"]}'):
reply_in_redis = await get_data_from_redis(f'{chat_id}_reply_{msg["id"]}')
if not reply_in_redis:
await save_data_to_redis(
f'{chat_id}_reply_{msg["id"]}',
reply["reply_body"]
Expand Down Expand Up @@ -138,7 +143,7 @@ async def get_data(state: FSMContext, bot: Bot):
data = await request_get(
URL + 'bot/',
headers=headers)
logging.info('Запрос сообщений')
logging.info(f'Запрос сообщений')
await get_messages(data, chat_id, bot)
await get_tasks(data, chat_id, bot)
except Exception:
Expand Down
5 changes: 4 additions & 1 deletion short_tracker_bot/short_tracker_bot/handlers/redis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ async def save_data_to_redis(key, value):
await redis.set(key, value)



async def get_data_from_redis(key):
data = await redis.get(key)
return data.decode('utf-8')
if data:
return data.decode('utf-8')
return None

0 comments on commit 28c1255

Please sign in to comment.