2024-05-31 00:18:58 +03:00
|
|
|
from datetime import datetime, timedelta
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2024-05-31 00:18:58 +03:00
|
|
|
import pytz
|
2023-08-27 23:43:16 +03:00
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
|
|
|
from classes.garbage_entry import GarbageEntry
|
|
|
|
from classes.pyroclient import PyroClient
|
2023-08-30 15:41:34 +03:00
|
|
|
from modules import custom_filters
|
2023-11-05 15:20:01 +02:00
|
|
|
from modules.database_api import col_entries
|
2023-08-27 23:43:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
@PyroClient.on_message(
|
2023-08-30 15:41:34 +03:00
|
|
|
~filters.scheduled & filters.private & filters.command(["upcoming"], prefixes=["/"]) & ~custom_filters.context # type: ignore
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
async def command_upcoming(app: PyroClient, message: Message):
|
|
|
|
user = await app.find_user(message.from_user)
|
|
|
|
|
|
|
|
if user.location is None:
|
|
|
|
await message.reply_text(
|
2023-09-25 00:47:09 +03:00
|
|
|
app._("location_empty", "messages", locale=user.locale)
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
date_min = (
|
2023-09-25 00:47:09 +03:00
|
|
|
datetime.now(user.location.timezone).replace(second=0, microsecond=0)
|
2024-05-31 00:18:58 +03:00
|
|
|
).replace(tzinfo=pytz.utc)
|
2023-08-27 23:43:16 +03:00
|
|
|
date_max = (
|
2023-09-25 00:47:09 +03:00
|
|
|
datetime.now(user.location.timezone).replace(second=0, microsecond=0)
|
2023-08-27 23:43:16 +03:00
|
|
|
+ timedelta(days=30)
|
2024-05-31 00:18:58 +03:00
|
|
|
).replace(tzinfo=pytz.utc)
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-30 14:00:21 +03:00
|
|
|
entries = [
|
|
|
|
await GarbageEntry.from_record(entry)
|
|
|
|
async for entry in col_entries.find(
|
|
|
|
{
|
|
|
|
"locations": user.location.id,
|
|
|
|
"date": {"$gte": date_min, "$lte": date_max},
|
|
|
|
}
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
2023-08-30 14:00:21 +03:00
|
|
|
]
|
2023-08-27 23:43:16 +03:00
|
|
|
|
|
|
|
entries_text = "\n\n".join(
|
|
|
|
[
|
2023-09-06 23:26:44 +03:00
|
|
|
f"**{entry.date.strftime(app._('date', 'formats', locale=user.locale))}**:\n{app._(str(entry.garbage_type.value), 'garbage_types', locale=user.locale)}"
|
2023-08-27 23:43:16 +03:00
|
|
|
for entry in entries
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
if not entries:
|
|
|
|
await message.reply_text(
|
2023-08-29 17:32:37 +03:00
|
|
|
app._("upcoming_empty", "messages", locale=user.locale).format(
|
|
|
|
name=user.location.name
|
|
|
|
)
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
2023-08-29 17:32:37 +03:00
|
|
|
await message.reply_text(
|
|
|
|
app._("upcoming", "messages", locale=user.locale).format(entries=entries_text)
|
|
|
|
)
|